php system_error ai_generated true

Warning: PHP Startup: Unable to allocate memory for interned strings buffer in Unknown on line 0

ID: php/opcache-interned-strings-buffer-overflow

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active

Root Cause

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.

generic

中文

opcache.interned_strings_buffer设置过大,超出可用内存,或实际驻留字符串使用量超过分配的缓冲区大小,导致PHP启动时失败。

Official Documentation

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

Workarounds

  1. 70% success Reduce opcache.interned_strings_buffer to a lower value, e.g., from 16 to 8 or 4 in php.ini, then restart PHP-FPM.
    Reduce opcache.interned_strings_buffer to a lower value, e.g., from 16 to 8 or 4 in php.ini, then restart PHP-FPM.
  2. 80% success 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
    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
  3. 85% success 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'];
    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'];

中文步骤

  1. Reduce opcache.interned_strings_buffer to a lower value, e.g., from 16 to 8 or 4 in php.ini, then restart PHP-FPM.
  2. 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
  3. 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'];

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Increasing the buffer without addressing memory constraints may cause the system to run out of memory entirely, leading to OOM kills or swap thrashing.

  2. 40% fail

    Disabling OPcache removes performance benefits and may mask the issue; interned strings buffer warnings may still appear if the setting is misconfigured.

  3. 90% fail

    Simply restarting does not resolve the underlying memory allocation issue; the warning will reappear on the next startup.