diff --git a/HotReload.php b/HotReload.php index 342fcfc..32d7fcf 100644 --- a/HotReload.php +++ b/HotReload.php @@ -1,4 +1,5 @@ startProcess(); - $bool = pcntl_signal(SIGINT | SIGQUIT | SIGTERM, function () { - $this->stopProcess(); - - $pid = (int)file_get_contents(storage('.swoole.pid')); - pcntl_waitpid($pid, $status); - }); - echo 'Listen signal ' . ($bool ? 'success' : 'fail') . PHP_EOL; + sleep(3); if (extension_loaded('inotify')) { $this->onInotifyReload(); } else { $this->onCrontabReload(); } + return 1; } @@ -148,6 +147,11 @@ class HotReload extends Command return; } + $pid = (int)file_get_contents(storage('.swoole.pid')); + if ($pid <= 0 || !Process::kill($pid, 0)) { + return; + } + $this->loadDirs(true); sleep(2); @@ -162,7 +166,7 @@ class HotReload extends Command * @return void * @throws Exception */ - private function loadByDir($path, $isReload = false): void + private function loadByDir($path, bool $isReload = false): void { if (!is_string($path)) { return; @@ -211,7 +215,7 @@ class HotReload extends Command /** * 开始监听 */ - public function check($inotify) + public function check($inotify): void { if (!($events = inotify_read($inotify))) { return;