我参观了许多论坛,但是我找不到解决问题的最佳解决方案。在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/inluminate/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不是最好的解决方案。
如果有人可以提供帮助。
谢谢
来自 random_bytes
文档:
用于此功能的随机性来源如下:
- 在Windows上,»cryptgenrandom((将始终使用。
- 在Linux上,如果可用,将使用»getrandom(2(Syscall。
- 在其他平台上,将使用
/dev/urandom
。- 如果没有上述来源可用,则将抛出一个例外。
所以,您的情况是最后一个。这不是您的代码问题,而是服务器设置。环境是什么?托管,云,虚拟服务器,本地计算机?