This commit is contained in:
2026-07-08 09:42:56 +08:00
parent 0adfe14a1f
commit 7f36bb0d53
5 changed files with 78 additions and 12 deletions
+26 -3
View File
@@ -245,15 +245,38 @@ class FileWatcher extends AbstractProcess implements OnProcessInterface
di(HotReloadState::class)->store($changedFiles);
di(StdoutLogger::class)->println('detected file changes, reloading server: ' . $preview);
$server = di(ServerInterface::class);
if (method_exists($server, 'reload')) {
$server->reload();
if (!$this->reloadWorkers()) {
di(StdoutLogger::class)->println('reload server failed: master pid not found or signal failed');
}
} finally {
$this->reloading = false;
}
}
private function reloadWorkers(): bool
{
$pid = $this->getMasterPid();
if ($pid === null) {
return false;
}
return Process::kill($pid, SIGUSR1);
}
private function getMasterPid(): ?int
{
$pidFile = function_exists('storage') ? storage('.swoole.pid') : '';
if (!is_file($pidFile)) {
return null;
}
$pid = (int)trim((string)file_get_contents($pidFile));
if ($pid <= 1 || !Process::kill($pid, 0)) {
return null;
}
return $pid;
}
private function startInotify(): void
{
$this->inotifyFd = inotify_init();