警告:PHP启动:无法为驻留字符串缓冲区分配内存,位置未知,行0
Warning: PHP Startup: Unable to allocate memory for interned strings buffer in Unknown on line 0
ID: php/opcache-interned-strings-buffer-overflow
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| PHP 8.1 | active | — | — | — |
| PHP 8.2 | active | — | — | — |
| PHP 8.3 | active | — | — | — |
根因分析
opcache.interned_strings_buffer设置过大,超出可用内存,或实际驻留字符串使用量超过分配的缓冲区大小,导致PHP启动时失败。
English
The opcache.interned_strings_buffer setting is too large for the available memory, or the actual interned strings usage exceeds the allocated buffer size, causing PHP to fail during startup.
官方文档
https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.interned-strings-buffer解决方案
-
Reduce opcache.interned_strings_buffer to a lower value, e.g., from 16 to 8 or 4 in php.ini, then restart PHP-FPM.
-
Increase system memory or adjust kernel parameters (e.g., vm.overcommit_memory) to allow larger allocations. On Linux, run: sudo sysctl -w vm.overcommit_memory=1
-
Monitor actual interned strings usage with opcache_get_status() and set the buffer to a value slightly above peak usage. Example: $status = opcache_get_status(false); echo $status['interned_strings_usage']['used_memory'];
无效尝试
常见但无效的做法:
-
60% 失败
Increasing the buffer without addressing memory constraints may cause the system to run out of memory entirely, leading to OOM kills or swap thrashing.
-
40% 失败
Disabling OPcache removes performance benefits and may mask the issue; interned strings buffer warnings may still appear if the setting is misconfigured.
-
90% 失败
Simply restarting does not resolve the underlying memory allocation issue; the warning will reappear on the next startup.