php system_error ai_generated true

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

ID: php/opcache-invalid-file

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active

Root Cause

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

中文

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

Official Documentation

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

Workarounds

  1. 90% success 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.
    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. 85% success Set opcache.validate_timestamps=1 and opcache.revalidate_freq=0 in php.ini to check file changes on every request, preventing stale entries.
    Set opcache.validate_timestamps=1 and opcache.revalidate_freq=0 in php.ini to check file changes on every request, preventing stale entries.
  3. 95% success 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.
    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. 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.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    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% fail

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