From c878ed0ba4519c17fad11ea05a0eada10a747260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 5 Nov 2021 14:22:57 +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 | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/kiri-engine/FileListen/FileChangeCustomProcess.php b/kiri-engine/FileListen/FileChangeCustomProcess.php index 78271ebc..d4ce6c3d 100644 --- a/kiri-engine/FileListen/FileChangeCustomProcess.php +++ b/kiri-engine/FileListen/FileChangeCustomProcess.php @@ -73,6 +73,7 @@ class FileChangeCustomProcess extends Command Coroutine::create(function () use ($driver) { $waite = Coroutine::waitSignal(SIGTERM | SIGKILL); if ($waite) { + $driver->clear(); $this->stop($driver); } }); @@ -85,20 +86,19 @@ class FileChangeCustomProcess extends Command /** * @throws Exception */ - private function stop($driver): void + private function stop(): void { - $driver->clear(); - if (!file_exists(storage('.swoole.pid'))) { - return; - } - $content = (int)file_get_contents(storage('.swoole.pid')); - if ($content > 0 && Process::kill($content, 0)) { - Process::kill($content, 15); - } - @unlink(storage('.swoole.pid')); +// if (!file_exists(storage('.swoole.pid'))) { +// return; +// } +// $content = (int)file_get_contents(storage('.swoole.pid')); +// if ($content > 0 && Process::kill($content, 0)) { +// Process::kill($content, 15); +// } +// @unlink(storage('.swoole.pid')); if (is_resource($this->source)) { - proc_close($this->source); + proc_terminate($this->source); $this->source = null; } } @@ -128,22 +128,9 @@ class FileChangeCustomProcess extends Command { Kiri::getDi()->get(Logger::class)->warning('change reload'); - if (file_exists(storage('.swoole.pid'))) { - $content = (int)file_get_contents(storage('.swoole.pid')); - if ($content > 0 && Process::kill($content, 0)) { - Process::kill($content, 15); - } - @unlink(storage('.swoole.pid')); - - if (is_resource($this->source)) { - proc_close($this->source); - $this->source = null; - } - } + $this->stop(); Coroutine::create(function () { - $descriptorspec = [0 => STDIN, 1 => STDOUT, 2 => STDERR]; - - $this->source = proc_open("php " . APP_PATH . "kiri.php", $descriptorspec, $pipes); + $this->source = proc_open("php " . APP_PATH . "kiri.php", [], $pipes); }); }