From 043b62688bb86863edebfdf80e9ceea73537bbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 4 Nov 2021 18:02:33 +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 --- .../FileListen/FileChangeCustomProcess.php | 18 +++++++++++++++--- kiri-engine/FileListen/Inotify.php | 2 -- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/kiri-engine/FileListen/FileChangeCustomProcess.php b/kiri-engine/FileListen/FileChangeCustomProcess.php index c1ec667d..1a7b67fb 100644 --- a/kiri-engine/FileListen/FileChangeCustomProcess.php +++ b/kiri-engine/FileListen/FileChangeCustomProcess.php @@ -30,6 +30,9 @@ class FileChangeCustomProcess extends Command public int $int = -1; + protected mixed $source; + + /** * */ @@ -60,10 +63,17 @@ class FileChangeCustomProcess extends Command $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); } $make = Barrier::make(); + go(function () { + $this->trigger_reload(); + }); go(function () { $sign = Coroutine::waitSignal(SIGTERM, -1); if ($sign) { - proc_open("php " . APP_PATH . "kiri.php sw:server stop", [], $pipes); + if ($this->source) { + proc_close($this->source); + } + $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server stop", [], $pipes); + proc_close($this->source); } }); go(function () use ($driver) { @@ -97,7 +107,9 @@ class FileChangeCustomProcess extends Command public function trigger_reload() { Kiri::getDi()->get(Logger::class)->warning('change reload'); - - proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $pipes); + if ($this->source) { + proc_close($this->source); + } + $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $pipes); } } diff --git a/kiri-engine/FileListen/Inotify.php b/kiri-engine/FileListen/Inotify.php index 6eea8467..785a3bdc 100644 --- a/kiri-engine/FileListen/Inotify.php +++ b/kiri-engine/FileListen/Inotify.php @@ -30,8 +30,6 @@ class Inotify */ public function start() { - $this->process->trigger_reload(); - $this->inotify = inotify_init(); $this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE; foreach ($this->dirs as $dir) {