# 警告：PHP 启动：无法分配内部字符串缓冲区：2097152 字节，位于 Unknown 第 0 行

- **ID:** `php/opcache-interned-strings-buffer`
- **领域:** php
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

OPcache 的内部字符串缓冲区太大，超出了可用的共享内存，通常是由于 `opcache.interned_strings_buffer` 配置值超过了系统的共享内存限制。

## 版本兼容性

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

## 解决方案

1. ```
   在 php.ini 中将 `opcache.interned_strings_buffer` 减小到较小的值，例如从 16 改为 8：`opcache.interned_strings_buffer = 8`
   ```
2. ```
   通过修改 `/etc/sysctl.conf` 增加系统共享内存限制：`kernel.shmmax = 2147483648` 和 `kernel.shmall = 2097152`，然后使用 `sysctl -p` 重新加载。
   ```
3. ```
   使用 `ipcs -lm` 检查可用共享内存，并将 `opcache.interned_strings_buffer` 调整为适合系统限制的值；安全起始值为 4 MB。
   ```

## 无效尝试

- **** — The error is about allocation failure; increasing the value increases memory demand. (95% 失败率)
- **** — The error only affects startup; disabling OPcache is unnecessary if the buffer size is adjusted. (60% 失败率)
- **** — The issue is a persistent configuration problem, not a transient system state. (90% 失败率)
