diff --git a/HotReload.php b/HotReload.php index e395f4d..72dfb36 100644 --- a/HotReload.php +++ b/HotReload.php @@ -21,7 +21,7 @@ class HotReload extends Command /** * @var Process */ - private Process $process; + private mixed $process; /** * @var array|mixed */ @@ -67,11 +67,7 @@ class HotReload extends Command */ private function startProcess(): void { - $process = new Process(function (Process $process) { - $process->exec(PHP_BINARY, [APP_PATH . 'kiri.php', 'sw:server', 'start']); - },); - $process->start(); - $this->process = $process; + $this->process = proc_open([PHP_BINARY, APP_PATH . 'kiri.php', 'sw:server', 'start'], [], $pipes); } @@ -272,7 +268,13 @@ class HotReload extends Command public function trigger_reload(): void { echo 'tigger server Reload' . PHP_EOL; - Process::kill($this->process->pid, SIGTERM); + if (is_resource($this->process)) { + $pid = (int)file_get_contents(storage('.swoole.pid')); + if (posix_kill($pid, 0)) { + posix_kill($pid, SIGTERM); + } + proc_close($this->process); + } $this->process = null; $this->startProcess(); } @@ -281,7 +283,7 @@ class HotReload extends Command /** * @throws Exception */ - public function clearWatch($inotify) + public function clearWatch($inotify): void { foreach ($this->watchFiles as $wd) { try { @@ -294,22 +296,6 @@ class HotReload extends Command } - /** - * @param $code - * @param $message - * @param $file - * @param $line - * @throws Exception - */ - protected function onErrorHandler($code, $message, $file, $line) - { - if (str_contains($message, 'The file descriptor is not an inotify instance')) { - return; - } - debug('Error:' . $message . ' at ' . $file . ':' . $line); - } - - /** * @param $inotify * @param $dir diff --git a/composer.json b/composer.json index 4f6b8d5..151ae4d 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "psr/http-server-middleware": "^1.0", "psr/http-message": "^1.0", "psr/event-dispatcher": "^1.0", - "ext-inotify": "*" + "ext-inotify": "*", + "ext-posix": "*" }, "autoload": { "psr-4": {