php
system_error
ai_generated
true
警告:openssl_random_pseudo_bytes():种子无法生成,位于 /var/www/app/src/Security/TokenGenerator.php 第 23 行
Warning: openssl_random_pseudo_bytes(): Seed could not be generated in /var/www/app/src/Security/TokenGenerator.php on line 23
ID: php/openssl-random-pseudo-bytes-seed
80%修复率
82%置信度
1证据数
2023-09-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| PHP 7.4 | active | — | — | — |
| PHP 8.0 | active | — | — | — |
| PHP 8.1 | active | — | — | — |
| PHP 8.2 | active | — | — | — |
根因分析
OpenSSL 随机数生成器无法收集足够的熵来播种,通常是由于系统中缺少或空的 /dev/urandom,或受限制的 open_basedir 配置。
English
The OpenSSL random number generator cannot gather enough entropy to seed, typically due to a missing or empty /dev/urandom on the system, or a restrictive open_basedir configuration.
官方文档
https://www.php.net/manual/en/function.openssl-random-pseudo-bytes.php解决方案
-
Check if /dev/urandom exists and is readable: `ls -la /dev/urandom`. If missing, create it: `sudo mknod -m 644 /dev/urandom c 1 9 && sudo chmod 644 /dev/urandom`. Then restart PHP-FPM.
-
If in a Docker container, ensure the container has access to the host's entropy pool by adding `--privileged` or mounting `/dev/urandom` from the host: `docker run -v /dev/urandom:/dev/urandom ...`
无效尝试
常见但无效的做法:
-
Increasing PHP's memory_limit or max_execution_time hoping the random generation will complete
95% 失败
The error is about entropy availability, not memory or time; the system simply cannot gather enough random data.
-
Installing haveged or rng-tools without verifying they are actually running and providing entropy
60% 失败
The service might be installed but not started, or the entropy source might be blocked by virtualization or container restrictions.