From 0cf17a547ea8f7e205dd6a4db8d29822767c151b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 4 Nov 2021 18:21:29 +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 | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/kiri-engine/FileListen/FileChangeCustomProcess.php b/kiri-engine/FileListen/FileChangeCustomProcess.php index 127d5edb..9625d5ee 100644 --- a/kiri-engine/FileListen/FileChangeCustomProcess.php +++ b/kiri-engine/FileListen/FileChangeCustomProcess.php @@ -64,22 +64,23 @@ 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) { - $this->closeProc(); - $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server stop", [ - STDIN, STDOUT - ], $this->pipes); - $this->closeProc(); } }); go(function () use ($driver) { $driver->start(); }); + $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server restart", + [ + 0 => ["pipe", "r"], // 标准输入,子进程从此管道中读取数据 + 1 => ["pipe", "w"], // 标准输出,子进程向此管道中写入数据 + 2 => ["file", "/tmp/error-output.txt", "a"] // 标准错误,写入到一个文件 + ] + , $this->pipes); + + var_dump($this->source, $this->pipes); Barrier::wait($make); return 0; } @@ -109,24 +110,11 @@ class FileChangeCustomProcess extends Command { Kiri::getDi()->get(Logger::class)->warning('change reload'); - if (is_resource($this->source)) { - fwrite($this->source, "php " . APP_PATH . "kiri.php sw:server restart"); - } else { - $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server restart", [ - STDIN, STDOUT - ], $this->pipes); - - var_dump($this->pipes); - } - - } + $this->source = proc_open("php " . APP_PATH . "kiri.php sw:server restart", [ + STDIN, STDOUT + ], $this->pipes); - private function closeProc() - { - foreach ($this->pipes as $pipe) { - fclose($pipe); - } } }