Invalidate changed PHP files before worker reload
This commit is contained in:
@@ -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[';
|
||||
|
||||
Reference in New Issue
Block a user