From 2bd18b014de646cc3a0938c408ed9304437ff4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 4 Nov 2021 18:06:10 +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 | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/kiri-engine/FileListen/FileChangeCustomProcess.php b/kiri-engine/FileListen/FileChangeCustomProcess.php index 7e6853bc..3c4ffba1 100644 --- a/kiri-engine/FileListen/FileChangeCustomProcess.php +++ b/kiri-engine/FileListen/FileChangeCustomProcess.php @@ -31,6 +31,7 @@ class FileChangeCustomProcess extends Command protected mixed $source = null; + protected mixed $pipes = []; /** @@ -69,11 +70,9 @@ class FileChangeCustomProcess extends Command go(function () { $sign = Coroutine::waitSignal(SIGTERM, -1); if ($sign) { - if (is_resource($this->source)) { - proc_close($this->source); - } - $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server stop", [], $pipes); - proc_close($this->source); + $this->closeProc(); + $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server stop", [], $this->pipes); + $this->closeProc(); } }); go(function () use ($driver) { @@ -107,9 +106,18 @@ class FileChangeCustomProcess extends Command public function trigger_reload() { Kiri::getDi()->get(Logger::class)->warning('change reload'); - if (is_resource($this->source)) { - proc_close($this->source); - } - $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $pipes); + + $this->closeProc(); + $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $this->pipes); } + + + private function closeProc() + { + foreach ($this->pipes as $pipe) { + fclose($pipe); + } + proc_close($this->source); + } + }