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

- **ID:** `php/opcache-invalid-file`
- **领域:** php
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — Disabling OPcache entirely (opcache.enable=0) fixes the warning but causes significant performance loss; it's an overreaction for a file management issue. (80% 失败率)
- **** — Simply restarting PHP-FPM without clearing the cache may not help if the file is still missing; the cache entry persists in shared memory. (65% 失败率)
