From 3fe9ab06c36b70b0bbc4fce4cb067caef9bfcdc8 Mon Sep 17 00:00:00 2001 From: whwyy Date: Wed, 8 Jul 2026 14:34:38 +0800 Subject: [PATCH] Invalidate changed PHP files before worker reload --- Abstracts/FileWatcher.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Abstracts/FileWatcher.php b/Abstracts/FileWatcher.php index 8bf537a..1edb253 100644 --- a/Abstracts/FileWatcher.php +++ b/Abstracts/FileWatcher.php @@ -291,6 +291,7 @@ class FileWatcher extends AbstractProcess implements OnProcessInterface try { $this->lastReloadAtMs = intdiv(hrtime(true), 1000000); + $this->invalidateChangedFiles($changedFiles); $preview = implode(', ', array_slice($changedFiles, 0, 3)); if (count($changedFiles) > 3) { $preview .= ' ...'; @@ -307,6 +308,23 @@ class FileWatcher extends AbstractProcess implements OnProcessInterface } } + private function invalidateChangedFiles(array $changedFiles): void + { + if (!function_exists('opcache_invalidate')) { + return; + } + + foreach ($changedFiles as $file) { + if (!is_string($file) || !str_ends_with($file, '.php')) { + continue; + } + + $path = realpath($file) ?: $file; + if (is_file($path)) { + @opcache_invalidate($path, true); + } + } + } private function isMasterProcessCommand(string $command): bool { $prefix = '[' . config('site.id', 'system-service') . '].Master[';