php system_error ai_generated true

警告: Opcache: 无法重新验证文件 '/var/www/app/index.php' - stat 失败,位于 Unknown 第 0 行

Warning: Opcache: Cannot revalidate file '/var/www/app/index.php' - stat failed in Unknown on line 0

ID: php/opcache-invalid-file

其他格式: JSON · Markdown 中文 · English
85%修复率
88%置信度
1证据数
2023-11-05首次发现

版本兼容性

版本状态引入弃用备注
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active

根因分析

OPcache 无法 stat 一个已缓存的 PHP 文件,因为该文件在缓存后被删除、移动或权限更改,导致缓存条目过时。

English

OPcache cannot stat a cached PHP file because the file was deleted, moved, or its permissions changed after being cached, causing a stale cache entry.

generic

官方文档

https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq

解决方案

  1. Clear the OPcache by restarting the web server (e.g., 'sudo systemctl restart php8.2-fpm') or using a function like opcache_reset() in a script.
  2. Set opcache.validate_timestamps=1 and opcache.revalidate_freq=0 in php.ini to check file changes on every request, preventing stale entries.
  3. Ensure the file exists and has correct permissions: run 'ls -la /var/www/app/index.php' and 'chmod 644 /var/www/app/index.php' if needed.

无效尝试

常见但无效的做法:

  1. 80% 失败

    Disabling OPcache entirely (opcache.enable=0) fixes the warning but causes significant performance loss; it's an overreaction for a file management issue.

  2. 65% 失败

    Simply restarting PHP-FPM without clearing the cache may not help if the file is still missing; the cache entry persists in shared memory.