PHP 致命错误:内部字符串缓冲区溢出,位于 /var/www/html/index.php 第 0 行
PHP Fatal error: Interned strings buffer overflow in /var/www/html/index.php on line 0
ID: php/opcache-interned-strings-corruption
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| PHP 8.1.27 | active | — | — | — |
| PHP 8.2.15 | active | — | — | — |
| PHP 8.3.3 | active | — | — | — |
根因分析
OPcache 的内部字符串缓冲区太小,无法容纳所有 PHP 文件中使用的唯一字符串总数,导致缓冲区溢出时发生内存损坏。
English
OPcache's interned strings buffer is too small for the total number of unique strings used across all PHP files, causing memory corruption when the buffer overflows.
官方文档
https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.interned-strings-buffer解决方案
-
Increase opcache.interned_strings_buffer in php.ini from default 8 MB to 16 MB or higher, then restart PHP-FPM: sudo systemctl restart php8.2-fpm
-
If the application uses many unique strings (e.g., dynamic SQL queries), reduce string duplication by using constants or shared helper functions to reuse common strings.
-
Monitor current interned strings usage with opcache_get_status()['interned_strings_usage'] and set buffer to 1.5x the peak usage.
无效尝试
常见但无效的做法:
-
60% 失败
Clearing OPcache files manually (rm -rf /tmp/opcache/) without restarting PHP-FPM often fails because the cache persists in shared memory.
-
80% 失败
Setting opcache.interned_strings_buffer to 0 (disable) can cause severe performance degradation and still trigger the error if any interned strings are used internally.
-
90% 失败
Adding more RAM to the server without adjusting the buffer size does not resolve the buffer overflow because the issue is configuration-based, not hardware-related.