php system_error ai_generated true

PHP Fatal error: Interned strings buffer overflow in /var/www/html/index.php on line 0

ID: php/opcache-interned-strings-corruption

Also available as: JSON · Markdown · 中文
88%Fix Rate
85%Confidence
1Evidence
2024-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
PHP 8.1.27 active
PHP 8.2.15 active
PHP 8.3.3 active

Root Cause

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.

generic

中文

OPcache 的内部字符串缓冲区太小,无法容纳所有 PHP 文件中使用的唯一字符串总数,导致缓冲区溢出时发生内存损坏。

Official Documentation

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

Workarounds

  1. 85% success 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
    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
  2. 75% success 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.
    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.
  3. 90% success Monitor current interned strings usage with opcache_get_status()['interned_strings_usage'] and set buffer to 1.5x the peak usage.
    Monitor current interned strings usage with opcache_get_status()['interned_strings_usage'] and set buffer to 1.5x the peak usage.

中文步骤

  1. 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
  2. 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.
  3. Monitor current interned strings usage with opcache_get_status()['interned_strings_usage'] and set buffer to 1.5x the peak usage.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Clearing OPcache files manually (rm -rf /tmp/opcache/) without restarting PHP-FPM often fails because the cache persists in shared memory.

  2. 80% fail

    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.

  3. 90% fail

    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.