From 8ec1a81ecd2219cc5fb8bf38e576b92a86f59fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 19 Nov 2021 10:20:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/FileListen/HotReload.php | 34 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index e64d12a7..9965dc9d 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -74,23 +74,33 @@ class HotReload extends Command swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); } $this->trigger_reload(); - Process::signal(SIGTERM | SIGKILL, function ($data) { - var_dump($data); - $this->driver->clear(); - $pid = file_get_contents(storage('.swoole.pid')); - if (!empty($pid) && Process::kill($pid, 0)) { - Process::kill($pid, SIGTERM); - } - while ($ret = Process::wait(true)) { - echo "PID={$ret['pid']}\n"; - sleep(1); - } - }); + + var_dump(getmypid()); + + Process::signal(SIGTERM, [$this, 'onSignal']); + Process::signal(SIGKILL, [$this, 'onSignal']); + $this->driver->start(); return 0; } + + public function onSignal($data) + { + var_dump($data); + $this->driver->clear(); + $pid = file_get_contents(storage('.swoole.pid')); + if (!empty($pid) && Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); + } + while ($ret = Process::wait(true)) { + echo "PID={$ret['pid']}\n"; + sleep(1); + } + } + + /** * @throws Exception */