我访问了很多论坛,但我找不到解决我的问题的最佳方案。在laravel 5中,我有这样的错误:
Cannot open source device in random_bytes() :
Exception in Str.php line 243:
Cannot open source device
in Str.php line 243
at random_bytes('25') in Str.php line 243
at Str::randomBytes('25') in Str.php line 227
at Str::random('25') in Store.php line 197
at Store->generateSessionId() in Store.php line 173该str.php位于: httpdocs/vendor/laravel/framework/src/Illuminate/Support/Str.php中:
/**
* Generate a more truly "random" alpha-numeric string.
*
* @param int $length
* @return string
*/
public static function random($length = 16)
{
$string = '';
while (($len = strlen($string)) < $length) {
$size = $length - $len;
$bytes = static::randomBytes($size);
$string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
}
return $string;
}
/**
* Generate a more truly "random" bytes.
*
* @param int $length
* @return string
*/
public static function randomBytes($length = 16)
{
return random_bytes($length);
}我使用php7。我也用openssl_random_pseudo_bytes()修改了random_bytes,这是正常的,但是我有另一个错误,框架不能为密码生成哈希。所以我认为openssl_random_bytes不是最好的解决方案。
如果有人能帮忙的话。
谢谢
发布于 2017-06-06 14:36:18
来自random_bytes documentation
此函数使用的随机性来源如下:
/dev/urandom。所以你的案子是最后一个了。这不是代码的问题,而是服务器设置的问题。环境是什么?托管、云、虚拟服务器、本地计算机?
https://stackoverflow.com/questions/44382744
复制相似问题