# PHP 致命错误：内部字符串缓冲区溢出，位于 /var/www/html/index.php 第 0 行

- **ID:** `php/opcache-interned-strings-corruption`
- **领域:** php
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PHP 8.1.27 | active | — | — |
| PHP 8.2.15 | active | — | — |
| PHP 8.3.3 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — Clearing OPcache files manually (rm -rf /tmp/opcache/) without restarting PHP-FPM often fails because the cache persists in shared memory. (60% 失败率)
- **** — 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. (80% 失败率)
- **** — 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. (90% 失败率)
