This commit is contained in:
2026-07-15 09:42:08 +08:00
parent 6ad9d5d0da
commit 136f360fec
3 changed files with 25 additions and 2 deletions
+1 -1
View File
@@ -307,7 +307,7 @@ class FileWatcher extends AbstractProcess implements OnProcessInterface
}
if (!$this->reloadWorkers()) {
di(StdoutLogger::class)->println('reload server failed: master pid not found or signal failed');
di(StdoutLogger::class)->println('reload server failed: Server->reload() failed, and master pid fallback not found or signal failed');
}
} finally {
$this->reloading = false;
+1 -1
View File
@@ -128,7 +128,7 @@ class HotReload extends AbstractProcess
$this->clear();
if (!$this->reloadWorkers()) {
di(StdoutLogger::class)->println('reload server failed: master pid not found or signal failed');
di(StdoutLogger::class)->println('reload server failed: Server->reload() failed, and master pid fallback not found or signal failed');
}
$this->addListen();
+23
View File
@@ -14,6 +14,10 @@ trait ReloadWorkers
*/
private function reloadWorkers(): bool
{
if ($this->reloadByServerInstance()) {
return true;
}
$pid = $this->getMasterPid();
if ($pid === null) {
return false;
@@ -22,6 +26,25 @@ trait ReloadWorkers
return Process::kill($pid, SIGUSR1);
}
private function reloadByServerInstance(): bool
{
try {
$server = function_exists('di') ? di(\Kiri\Server\ServerInterface::class) : null;
} catch (\Throwable) {
return false;
}
if (!is_object($server) || !method_exists($server, 'reload')) {
return false;
}
try {
return $server->reload() !== false;
} catch (\Throwable) {
return false;
}
}
private function getMasterPid(): ?int
{
if (self::$cachedMasterPid !== null && $this->isCachedMasterPid(self::$cachedMasterPid)) {