Be careful when setting the 'strong' parameter to true.
If you system doesn't have enough entropy your script will block which can cause timeouts in other parts of your code.
In my case, the most serious symptom was my script blocking when trying to read from /dev/random and causing a 'MySQL has gone away' error.
Hopefully this saves someone the trouble when deciding to use /dev/random entropyOAuthProvider::generateToken
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
OAuthProvider::generateToken
Референца за `oauthprovider.generatetoken.php` со подобрена типографија и навигација.
OAuthProvider::generateToken
(PECL OAuth >= 1.0.0)
OAuthProvider::generateToken — Generate a random token
= NULL
Генерира string of pseudo-random bytes.
Параметри
size- The desired token length, in terms of bytes.
strong-
Поставување на
truemeans/dev/randomwill be used for entropy, as otherwise the non-blocking/dev/urandomis used. This parameter is ignored on Windows.
Вратени вредности
The generated token, as a string Враќа генериран
Errors/Exceptions
Ако strong параметарот е trueсе фрла исклучок.
E_WARNING level error will be emitted when the fallback rand() implementation is used to fill the remaining random bytes (e.g., when not enough random data was found, initially).
Примери
Пример #1 OAuthProvider::generateToken() example
<?php
$p = new OAuthProvider();
$t = $p->generateToken(4);
echo strlen($t), PHP_EOL;
echo bin2hex($t), PHP_EOL;
?>Горниот пример ќе прикаже нешто слично на:
4 b6a82c27
Белешки
Забелешка: When not enough random data is available to the system, this function will fill the remaining random bytes using the internal PHP rand() implementation.
Види Исто така
- openssl_random_pseudo_bytes() - Генерира псевдо-случајна низа од бајти
- mcrypt_create_iv() - Создава вектор за иницијализација (IV) од случаен извор