# 警告：openssl_random_pseudo_bytes()：种子无法生成，位于 /var/www/app/src/Security/TokenGenerator.php 第 23 行

- **ID:** `php/openssl-random-pseudo-bytes-seed`
- **领域:** php
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

OpenSSL 随机数生成器无法收集足够的熵来播种，通常是由于系统中缺少或空的 /dev/urandom，或受限制的 open_basedir 配置。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PHP 7.4 | active | — | — |
| PHP 8.0 | active | — | — |
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |

## 解决方案

1. ```
   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.
   ```
2. ```
   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** — The error is about entropy availability, not memory or time; the system simply cannot gather enough random data. (95% 失败率)
- **Installing haveged or rng-tools without verifying they are actually running and providing entropy** — The service might be installed but not started, or the entropy source might be blocked by virtualization or container restrictions. (60% 失败率)
