【发布时间】:2017-06-06 06:24:48
【问题描述】:
我访问了很多论坛,但我找不到解决问题的最佳方法。 在 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);
}
我使用 php 7。我还通过 openssl_random_pseudo_bytes() 更改了 random_bytes,它可以工作,但我有另一个错误,即框架无法为密码生成哈希。所以我认为 openssl_random_bytes 不是最好的解决方案。
如果有人可以提供帮助。
谢谢
【问题讨论】:
-
您使用的是哪个版本的 PHP 7?
-
这 : # php -v PHP 7.0.19 (cli) (built: May 12 2017 21:01:27) (NTS) 版权所有 (c) 1997-2017 The PHP Group Zend Engine v3. 0.0,版权所有 (c) 1998-2017 Zend Technologies
-
我遇到了类似的问题和很多段错误,我升级到 PHP 7.1.1,它们现在可以正常工作了。
-
我安装了 PHP 7.1.5,但我有同样的错误:PHP 7.1.5 (cli) (built: May 12 2017 21:54:58) (NTS) 版权所有 (c) 1997-2017 PHP Group Zend Engine v3.1.0,版权所有 (c) 1998-2017 Zend Technologies 和 Zend OPcache v7.1.5,版权所有 (c) 1999-2017,Zend Technologies