Invalidate changed PHP files before worker reload

This commit is contained in:
2026-07-08 14:34:38 +08:00
parent a61e83ff6a
commit 3fe9ab06c3
+18
View File
@@ -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[';