php system_error ai_generated true

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

Warning: PHP Startup: Unable to allocate interned strings buffer: 2097152 bytes in Unknown on line 0

ID: php/opcache-interned-strings-buffer

其他格式: JSON · Markdown 中文 · English
90%修复率
88%置信度
1证据数
2023-08-22首次发现

版本兼容性

版本状态引入弃用备注
PHP 8.0 active
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active
OPcache 8.0 active
OPcache 8.1 active

根因分析

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

English

OPcache's interned strings buffer is too large for the available shared memory, typically due to a misconfigured `opcache.interned_strings_buffer` value exceeding the system's shared memory limits.

generic

官方文档

https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.interned-strings-buffer

解决方案

  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。

无效尝试

常见但无效的做法:

  1. 95% 失败

    The error is about allocation failure; increasing the value increases memory demand.

  2. 60% 失败

    The error only affects startup; disabling OPcache is unnecessary if the buffer size is adjusted.

  3. 90% 失败

    The issue is a persistent configuration problem, not a transient system state.