From d587d418513fe26d3e6ceb522fbd314bca2679c4 Mon Sep 17 00:00:00 2001 From: xl Date: Mon, 10 Jul 2023 10:36:45 +0800 Subject: [PATCH] qqq --- HotReload.php | 54 ++++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/HotReload.php b/HotReload.php index 4246d86..e2e2f72 100644 --- a/HotReload.php +++ b/HotReload.php @@ -6,6 +6,7 @@ namespace Kiri\Server; use Exception; use Kiri\Di\Context; use Kiri\Server\Abstracts\BaseProcess; +use ReflectionException; use Swoole\Coroutine; use Swoole\Event; use Swoole\Process; @@ -48,48 +49,27 @@ class HotReload extends BaseProcess if (Context::inCoroutine()) { Coroutine::create(fn() => $this->onShutdown(Coroutine::waitSignal(SIGTERM | SIGINT))); } else { - Process::signal(SIGTERM, function ($data) { - - var_dump('收到消息'); - - foreach ($this->watchFiles as $file) { - @inotify_rm_watch($file, $this->inotify); - } - $this->onShutdown($data); - }); - Process::signal(SIGINT, function ($data) { - - var_dump('收到消息'); - - foreach ($this->watchFiles as $file) { - @inotify_rm_watch($file, $this->inotify); - } - $this->onShutdown($data); - }); - - pcntl_signal(SIGTERM, function ($data) { - - var_dump('收到消息'); - - foreach ($this->watchFiles as $file) { - @inotify_rm_watch($file, $this->inotify); - } - $this->onShutdown($data); - }); - pcntl_signal(SIGINT, function ($data) { - - var_dump('收到消息'); - - foreach ($this->watchFiles as $file) { - @inotify_rm_watch($file, $this->inotify); - } - $this->onShutdown($data); - }); + pcntl_signal(SIGTERM, [$this, 'onStop']); + pcntl_signal(SIGINT, [$this, 'onStop']); } return $this; } + /** + * @param $data + * @return void + * @throws ReflectionException + */ + public function onStop($data): void + { + foreach ($this->watchFiles as $file) { + @inotify_rm_watch($file, $this->inotify); + } + $this->onShutdown($data); + } + + /** * @param Process|null $process * @return void