From 873da66a90e8fc64c51b1e24f6e444289812e637 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 02:20:04 +0800 Subject: [PATCH 01/41] 1 --- kiri-engine/FileListen/HotReload.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 88d99f95..af3a30e4 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -72,16 +72,11 @@ class HotReload extends Command swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); } $this->trigger_reload(); - Process::signal(SIGTERM | SIGKILL, function ($data) { - var_dump($data); + pcntl_signal(SIGTERM | SIGKILL, function ($data) { $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } - while ($ret = Process::wait(true)) { - echo "PID={$ret['pid']}\n"; - sleep(1); - } }); $driver->start(); return 0; From 841a6b4a199ef9d652dbfbe10cb23fb758dfbd3c Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 02:50:39 +0800 Subject: [PATCH 02/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index af3a30e4..d2e89ae3 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -73,6 +73,7 @@ class HotReload extends Command } $this->trigger_reload(); pcntl_signal(SIGTERM | SIGKILL, function ($data) { + var_dump($data); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); From 0a6fdda7200fb75d0040b5574d18443e9cead362 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 02:54:05 +0800 Subject: [PATCH 03/41] 1 --- kiri-engine/FileListen/HotReload.php | 235 ++++++++++++++------------- 1 file changed, 120 insertions(+), 115 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index d2e89ae3..c9f6f54b 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -21,142 +21,147 @@ class HotReload extends Command { - public bool $isReloading = false; - public bool $isReloadingOut = false; - public ?array $dirs = []; + public bool $isReloading = FALSE; + public bool $isReloadingOut = FALSE; + public ?array $dirs = []; - public int $events; + public int $events; - public int $int = -1; + public int $int = -1; - private ?Process $process = null; + private ?Process $process = NULL; - protected mixed $source = null; + protected mixed $source = NULL; - protected mixed $pipes = []; + protected mixed $pipes = []; - protected ?Coroutine\Channel $channel = null; + protected ?Coroutine\Channel $channel = NULL; - /** - * - */ - protected function configure() - { - $this->setName('sw:wather') - ->setDescription('server start'); - } + /** + * + */ + protected function configure() + { + $this->setName('sw:wather') + ->setDescription('server start'); + } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - * @throws ConfigException - * @throws Exception - */ - public function execute(InputInterface $input, OutputInterface $output): int - { - // TODO: Implement onHandler() method. - set_error_handler([$this, 'onErrorHandler']); + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + * @throws ConfigException + * @throws Exception + */ + public function execute(InputInterface $input, OutputInterface $output): int + { + // TODO: Implement onHandler() method. + set_error_handler([$this, 'onErrorHandler']); - $this->dirs = Config::get('inotify', [APP_PATH . 'app']); - if (!extension_loaded('inotify')) { - $driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]); - } else { - $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); - } - if (Kiri::getPlatform()->isLinux()) { - swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); - } - $this->trigger_reload(); - pcntl_signal(SIGTERM | SIGKILL, function ($data) { - var_dump($data); - $pid = file_get_contents(storage('.swoole.pid')); - if (!empty($pid) && Process::kill($pid, 0)) { - Process::kill($pid, SIGTERM); - } - }); - $driver->start(); - return 0; - } + $this->dirs = Config::get('inotify', [APP_PATH . 'app']); + if (!extension_loaded('inotify')) { + $driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]); + } else { + $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); + } + if (Kiri::getPlatform()->isLinux()) { + swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); + } + $this->trigger_reload(); + Process::signal(SIGKILL, [$this, 'onSignal']); + Process::signal(SIGTERM, [$this, 'onSignal']); + $driver->start(); + return 0; + } - /** - * @throws Exception - */ - public function onExit() - { - $data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1); - if ($data) { - $pid = file_get_contents(storage('.swoole.pid')); - if (!empty($pid) && Process::kill($pid, 0)) { - Process::kill($pid, SIGTERM); - } - $this->stop(); - $this->source = null; - } - } + public function onSignal($data) + { + var_dump($data); + $pid = file_get_contents(storage('.swoole.pid')); + if (!empty($pid) && Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); + } + } - /** - * @throws Exception - */ - private function stop(): void - { - if (is_resource($this->source)) { - proc_terminate($this->source); - while (proc_get_status($this->source)['running']) { - Coroutine::sleep(1); - var_dump(proc_get_status($this->source)['running']); - } - var_dump(proc_get_status($this->source)['running']); - proc_close($this->source); - var_dump('isClose.'); - $this->source = null; - } - } + /** + * @throws Exception + */ + public function onExit() + { + $data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1); + if ($data) { + $pid = file_get_contents(storage('.swoole.pid')); + if (!empty($pid) && Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); + } + $this->stop(); + $this->source = NULL; + } + } - /** - * @param $code - * @param $message - * @param $file - * @param $line - * @throws Exception - */ - public function onErrorHandler($code, $message, $file, $line) - { - if (str_contains($message, 'The file descriptor is not an inotify instance')) { - return; - } - debug('Error:' . $message . ' at ' . $file . ':' . $line); - } + /** + * @throws Exception + */ + private function stop(): void + { + if (is_resource($this->source)) { + proc_terminate($this->source); + while (proc_get_status($this->source)['running']) { + Coroutine::sleep(1); + var_dump(proc_get_status($this->source)['running']); + } + var_dump(proc_get_status($this->source)['running']); + proc_close($this->source); + var_dump('isClose.'); + $this->source = NULL; + } + } - /** - * 重启 - * - * @throws Exception - */ - public function trigger_reload() - { - Kiri::getDi()->get(Logger::class)->warning('change reload'); - if ($this->process instanceof Process && Process::kill($this->process->pid, 0)) { - $pid = file_get_contents(storage('.swoole.pid')); - if (!empty($pid) && Process::kill($pid, 0)) { - Process::kill($pid, SIGTERM); - } - Process::kill($this->process->pid, SIGTERM); - Process::wait(true); - } - $this->process = new Process(function (Process $process) { - $process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]); - }); - $this->process->start(); - } + /** + * @param $code + * @param $message + * @param $file + * @param $line + * @throws Exception + */ + public function onErrorHandler($code, $message, $file, $line) + { + if (str_contains($message, 'The file descriptor is not an inotify instance')) { + return; + } + debug('Error:' . $message . ' at ' . $file . ':' . $line); + } + + + /** + * 重启 + * + * @throws Exception + */ + public function trigger_reload() + { + Kiri::getDi()->get(Logger::class)->warning('change reload'); + if ($this->process instanceof Process && Process::kill($this->process->pid, 0)) { + $pid = file_get_contents(storage('.swoole.pid')); + if (!empty($pid) && Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); + } + Process::kill($this->process->pid, SIGTERM); + Process::wait(TRUE); + } + $this->process = new Process(function (Process $process) { + $process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]); + }); + $this->process->start(); + } } From 07c52ef08f871fd137a16654a83b440afc474973 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 02:55:34 +0800 Subject: [PATCH 04/41] 1 --- kiri-engine/FileListen/HotReload.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index c9f6f54b..d4f466f8 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -3,6 +3,7 @@ namespace Kiri\FileListen; use Exception; +use JetBrains\PhpStorm\NoReturn; use Kiri\Abstracts\Config; use Kiri\Abstracts\Logger; use Kiri\Exception\ConfigException; @@ -79,13 +80,16 @@ class HotReload extends Command } - public function onSignal($data) + /** + * @throws Exception + */ + #[NoReturn] public function onSignal($data) { - var_dump($data); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } + exit(0); } From 9986900b585a42bca7efe1eadac95e8472818c7d Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 02:56:34 +0800 Subject: [PATCH 05/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index d4f466f8..267ec74f 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -80,6 +80,7 @@ class HotReload extends Command } + /** * @throws Exception */ From 2393ef820f5c4f58cc0a2085127d00a875f871c1 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:01:17 +0800 Subject: [PATCH 06/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 267ec74f..601aefe4 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -81,6 +81,7 @@ class HotReload extends Command + /** * @throws Exception */ From 5156a606e0064b2d026bd7f135f7e232b3025e1c Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:03:00 +0800 Subject: [PATCH 07/41] 1 --- kiri-engine/FileListen/HotReload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 601aefe4..129d3848 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -165,7 +165,7 @@ class HotReload extends Command } $this->process = new Process(function (Process $process) { $process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]); - }); + },null,null,FALSE); $this->process->start(); } From ffc35090b9d6c76a67a6e842d073d9688c27318c Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:03:15 +0800 Subject: [PATCH 08/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 129d3848..58a2544f 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -147,6 +147,7 @@ class HotReload extends Command } + /** * 重启 * From fa78d360b008073e8907464df9dfab76a51a7120 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:21:21 +0800 Subject: [PATCH 09/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 58a2544f..4207eb26 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -81,7 +81,6 @@ class HotReload extends Command - /** * @throws Exception */ From 5638d171d0a2f46ca95efa0987252bb3bfbca2fa Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:24:09 +0800 Subject: [PATCH 10/41] 1 --- kiri-engine/FileListen/HotReload.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 4207eb26..877c6832 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -9,6 +9,7 @@ use Kiri\Abstracts\Logger; use Kiri\Exception\ConfigException; use Kiri\Kiri; use Swoole\Coroutine; +use Swoole\Event; use Swoole\Process; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -31,6 +32,8 @@ class HotReload extends Command public int $int = -1; + private Scaner|Inotify $driver; + private ?Process $process = NULL; @@ -65,9 +68,9 @@ class HotReload extends Command $this->dirs = Config::get('inotify', [APP_PATH . 'app']); if (!extension_loaded('inotify')) { - $driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]); + $this->driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]); } else { - $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); + $this->driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); } if (Kiri::getPlatform()->isLinux()) { swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); @@ -75,7 +78,7 @@ class HotReload extends Command $this->trigger_reload(); Process::signal(SIGKILL, [$this, 'onSignal']); Process::signal(SIGTERM, [$this, 'onSignal']); - $driver->start(); + $this->driver->start(); return 0; } @@ -90,7 +93,7 @@ class HotReload extends Command if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } - exit(0); + $this->driver->clear(); } From 114f5d0279f7b9d47dc45c783c76e63a19233d44 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:27:07 +0800 Subject: [PATCH 11/41] 1 --- kiri-engine/FileListen/Inotify.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kiri-engine/FileListen/Inotify.php b/kiri-engine/FileListen/Inotify.php index 01558bc1..bd8040b6 100644 --- a/kiri-engine/FileListen/Inotify.php +++ b/kiri-engine/FileListen/Inotify.php @@ -51,9 +51,10 @@ class Inotify } - /** - * 开始监听 - */ + /** + * 开始监听 + * @throws Exception + */ public function check() { if (!($events = inotify_read($this->inotify))) { @@ -75,7 +76,10 @@ class Inotify if ($this->process->int !== -1) { return; } - $this->process->int = @swoole_timer_after(2000, [$this, 'reload']); + + usleep(200); + + $this->reload(); $this->process->isReloading = true; } From f6552c45ae2c0deaf0ec527a5bcbdca28df6ac29 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:27:30 +0800 Subject: [PATCH 12/41] 1 --- kiri-engine/FileListen/Inotify.php | 1 - 1 file changed, 1 deletion(-) diff --git a/kiri-engine/FileListen/Inotify.php b/kiri-engine/FileListen/Inotify.php index bd8040b6..ea83a547 100644 --- a/kiri-engine/FileListen/Inotify.php +++ b/kiri-engine/FileListen/Inotify.php @@ -155,7 +155,6 @@ class Inotify } else if (!str_ends_with($f, '.php')) { continue; } - //检测文件类型 if (strstr($f, '.') == '.php') { $wd = @inotify_add_watch($this->inotify, $path, $this->events); From ea09d3e3baf307d85980e80568db28d295929f20 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:36:35 +0800 Subject: [PATCH 13/41] 1 --- kiri-engine/FileListen/HotReload.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 877c6832..18ff81ea 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -83,7 +83,6 @@ class HotReload extends Command } - /** * @throws Exception */ @@ -149,7 +148,6 @@ class HotReload extends Command } - /** * 重启 * @@ -158,18 +156,14 @@ class HotReload extends Command public function trigger_reload() { Kiri::getDi()->get(Logger::class)->warning('change reload'); - if ($this->process instanceof Process && Process::kill($this->process->pid, 0)) { - $pid = file_get_contents(storage('.swoole.pid')); - if (!empty($pid) && Process::kill($pid, 0)) { - Process::kill($pid, SIGTERM); - } - Process::kill($this->process->pid, SIGTERM); + $pid = file_get_contents(storage('.swoole.pid')); + if (!empty($pid) && Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); Process::wait(TRUE); } - $this->process = new Process(function (Process $process) { - $process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]); - },null,null,FALSE); - $this->process->start(); + Coroutine::create(function () { + proc_open('php ' . APP_PATH . ' kiri.php sw:server restart', [], $pipes); + }); } From cac794ca2039aaa4f5da4c51f00a7e65c1fa1738 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:37:57 +0800 Subject: [PATCH 14/41] 1 --- kiri-engine/FileListen/HotReload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 18ff81ea..7066fdb3 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -148,6 +148,7 @@ class HotReload extends Command } + /** * 重启 * @@ -159,7 +160,6 @@ class HotReload extends Command $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); - Process::wait(TRUE); } Coroutine::create(function () { proc_open('php ' . APP_PATH . ' kiri.php sw:server restart', [], $pipes); From ba804c4d9c98ae357923008d97019a62a7df03f8 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:42:23 +0800 Subject: [PATCH 15/41] 1 --- kiri-engine/FileListen/HotReload.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 7066fdb3..bc7b630a 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -78,7 +78,9 @@ class HotReload extends Command $this->trigger_reload(); Process::signal(SIGKILL, [$this, 'onSignal']); Process::signal(SIGTERM, [$this, 'onSignal']); - $this->driver->start(); + Coroutine\run(function (){ + $this->driver->start(); + }); return 0; } From 758bd650b576fd122ea4ed524c840be750c8fa91 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:43:00 +0800 Subject: [PATCH 16/41] 1 --- kiri-engine/FileListen/HotReload.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index bc7b630a..15f109ea 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -78,7 +78,7 @@ class HotReload extends Command $this->trigger_reload(); Process::signal(SIGKILL, [$this, 'onSignal']); Process::signal(SIGTERM, [$this, 'onSignal']); - Coroutine\run(function (){ + Coroutine::create(function () { $this->driver->start(); }); return 0; @@ -150,7 +150,6 @@ class HotReload extends Command } - /** * 重启 * From dbc4cb15dd36d742fc35d201b80fbb1cc8b77aab Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:43:29 +0800 Subject: [PATCH 17/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 15f109ea..785294cc 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -162,6 +162,7 @@ class HotReload extends Command if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } + var_dump('d'); Coroutine::create(function () { proc_open('php ' . APP_PATH . ' kiri.php sw:server restart', [], $pipes); }); From 43a1fad278c401f9a41a073aeaa0b6b757da7561 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:45:18 +0800 Subject: [PATCH 18/41] 1 --- kiri-engine/FileListen/HotReload.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 785294cc..aa896227 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -76,9 +76,13 @@ class HotReload extends Command swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); } $this->trigger_reload(); - Process::signal(SIGKILL, [$this, 'onSignal']); - Process::signal(SIGTERM, [$this, 'onSignal']); Coroutine::create(function () { + Coroutine::create(function () { + $this->onSignal(Coroutine::waitSignal(SIGKILL, -1)); + }); + Coroutine::create(function () { + $this->onSignal(Coroutine::waitSignal(SIGTERM, -1)); + }); $this->driver->start(); }); return 0; From 092139c0b9a91784bde9831ca1b9026c947fc7a1 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:46:10 +0800 Subject: [PATCH 19/41] 1 --- kiri-engine/FileListen/HotReload.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index aa896227..7757cef2 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -168,8 +168,9 @@ class HotReload extends Command } var_dump('d'); Coroutine::create(function () { - proc_open('php ' . APP_PATH . ' kiri.php sw:server restart', [], $pipes); + proc_open('php ' . APP_PATH . '/kiri.php sw:server restart', [], $pipes); }); + } From f72c73766d4c7979a19e86053e50cff048c24c82 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:46:29 +0800 Subject: [PATCH 20/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 7757cef2..1af83519 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -154,6 +154,7 @@ class HotReload extends Command } + /** * 重启 * From 1c18ee94ee1f48df114dd97310537c35d91c4f5a Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:48:16 +0800 Subject: [PATCH 21/41] 1 --- kiri-engine/FileListen/HotReload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 1af83519..f3673ccb 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -95,6 +95,7 @@ class HotReload extends Command #[NoReturn] public function onSignal($data) { $pid = file_get_contents(storage('.swoole.pid')); + var_dump($pid); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } @@ -167,7 +168,6 @@ class HotReload extends Command if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } - var_dump('d'); Coroutine::create(function () { proc_open('php ' . APP_PATH . '/kiri.php sw:server restart', [], $pipes); }); From c5bfe8110ae828fdd2c2f2db5634f5f96a145ca6 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:48:54 +0800 Subject: [PATCH 22/41] 1 --- kiri-engine/FileListen/HotReload.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index f3673ccb..c68afc44 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -78,10 +78,7 @@ class HotReload extends Command $this->trigger_reload(); Coroutine::create(function () { Coroutine::create(function () { - $this->onSignal(Coroutine::waitSignal(SIGKILL, -1)); - }); - Coroutine::create(function () { - $this->onSignal(Coroutine::waitSignal(SIGTERM, -1)); + $this->onSignal(Coroutine::waitSignal(SIGKILL & SIGTERM, -1)); }); $this->driver->start(); }); From d3ed35e9486cbf9a54af5d3bbb6261505f551ba8 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:50:47 +0800 Subject: [PATCH 23/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index c68afc44..03ff5ac3 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -168,7 +168,6 @@ class HotReload extends Command Coroutine::create(function () { proc_open('php ' . APP_PATH . '/kiri.php sw:server restart', [], $pipes); }); - } From 5d91b61f83cc495d0c602877a7e8de73c09c877a Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:51:41 +0800 Subject: [PATCH 24/41] 1 --- kiri-engine/FileListen/HotReload.php | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 03ff5ac3..95ecb8de 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -92,7 +92,6 @@ class HotReload extends Command #[NoReturn] public function onSignal($data) { $pid = file_get_contents(storage('.swoole.pid')); - var_dump($pid); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } @@ -100,23 +99,6 @@ class HotReload extends Command } - /** - * @throws Exception - */ - public function onExit() - { - $data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1); - if ($data) { - $pid = file_get_contents(storage('.swoole.pid')); - if (!empty($pid) && Process::kill($pid, 0)) { - Process::kill($pid, SIGTERM); - } - $this->stop(); - $this->source = NULL; - } - } - - /** * @throws Exception */ @@ -126,11 +108,8 @@ class HotReload extends Command proc_terminate($this->source); while (proc_get_status($this->source)['running']) { Coroutine::sleep(1); - var_dump(proc_get_status($this->source)['running']); } - var_dump(proc_get_status($this->source)['running']); proc_close($this->source); - var_dump('isClose.'); $this->source = NULL; } } @@ -165,8 +144,9 @@ class HotReload extends Command if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } + $this->stop(); Coroutine::create(function () { - proc_open('php ' . APP_PATH . '/kiri.php sw:server restart', [], $pipes); + $this->source = proc_open('php ' . APP_PATH . '/kiri.php sw:server restart', [], $pipes); }); } From f243e19b24b28c7b272bd8de330304fa49ca7634 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:52:44 +0800 Subject: [PATCH 25/41] 1 --- kiri-engine/FileListen/HotReload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 95ecb8de..d46637e7 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -78,7 +78,7 @@ class HotReload extends Command $this->trigger_reload(); Coroutine::create(function () { Coroutine::create(function () { - $this->onSignal(Coroutine::waitSignal(SIGKILL & SIGTERM, -1)); + $this->onSignal(Coroutine::waitSignal(SIGKILL | SIGTERM, -1)); }); $this->driver->start(); }); From abcf5e9febdd82172a1763ee8d82358a83d8385a Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:53:57 +0800 Subject: [PATCH 26/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index d46637e7..2efcd6e1 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -91,6 +91,7 @@ class HotReload extends Command */ #[NoReturn] public function onSignal($data) { + var_dump($data); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); From 755594b4bbf364a3d4dac921a5c26cfb6157d916 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:54:31 +0800 Subject: [PATCH 27/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 2efcd6e1..ccfaf565 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -86,6 +86,7 @@ class HotReload extends Command } + /** * @throws Exception */ From f3446da34edc0d2aa8eb548d6fc67a907f8ea4a7 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:57:24 +0800 Subject: [PATCH 28/41] 1 --- kiri-engine/FileListen/Inotify.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kiri-engine/FileListen/Inotify.php b/kiri-engine/FileListen/Inotify.php index ea83a547..8f8d1676 100644 --- a/kiri-engine/FileListen/Inotify.php +++ b/kiri-engine/FileListen/Inotify.php @@ -47,6 +47,9 @@ class Inotify public function clear() { Event::del($this->inotify); + + var_dump('clear event'); + Event::exit(); } From 7aee3c8458453d0256713170e81ac5f3ffc87141 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:59:04 +0800 Subject: [PATCH 29/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index ccfaf565..bb4d7f5d 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -97,6 +97,7 @@ class HotReload extends Command if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } + var_dump('over'); $this->driver->clear(); } From fbd7f874ac82dd0b41617b61daa6bacd7ed47bbd Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:59:15 +0800 Subject: [PATCH 30/41] 1 --- kiri-engine/FileListen/HotReload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index bb4d7f5d..a583d808 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -93,12 +93,12 @@ class HotReload extends Command #[NoReturn] public function onSignal($data) { var_dump($data); + $this->driver->clear(); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); } var_dump('over'); - $this->driver->clear(); } From 59243a6fed4e3d1927c2988e2a266c072f73a491 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 03:59:36 +0800 Subject: [PATCH 31/41] 1 --- kiri-engine/FileListen/HotReload.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index a583d808..a9c0548b 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -85,8 +85,7 @@ class HotReload extends Command return 0; } - - + /** * @throws Exception */ From 0f238f488d1c7271d2bb4a57d900f111ccd91dba Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:00:31 +0800 Subject: [PATCH 32/41] 1 --- kiri-engine/FileListen/HotReload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index a9c0548b..4b2a3cee 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -85,7 +85,7 @@ class HotReload extends Command return 0; } - + /** * @throws Exception */ @@ -95,7 +95,7 @@ class HotReload extends Command $this->driver->clear(); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { - Process::kill($pid, SIGTERM); + var_dump(Process::kill($pid, SIGTERM)); } var_dump('over'); } From 2f038e56378c95c533f0574459e7148e8c1ec653 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:02:40 +0800 Subject: [PATCH 33/41] 1 --- kiri-engine/FileListen/HotReload.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 4b2a3cee..d86c45fb 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -2,6 +2,7 @@ namespace Kiri\FileListen; +use Annotation\Inject; use Exception; use JetBrains\PhpStorm\NoReturn; use Kiri\Abstracts\Config; @@ -32,6 +33,10 @@ class HotReload extends Command public int $int = -1; + #[Inject(Logger::class)] + public Logger $logger; + + private Scaner|Inotify $driver; private ?Process $process = NULL; @@ -91,13 +96,14 @@ class HotReload extends Command */ #[NoReturn] public function onSignal($data) { - var_dump($data); $this->driver->clear(); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { - var_dump(Process::kill($pid, SIGTERM)); + while (Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); + } } - var_dump('over'); + $this->logger->notice('over'); } @@ -133,7 +139,6 @@ class HotReload extends Command } - /** * 重启 * @@ -141,7 +146,7 @@ class HotReload extends Command */ public function trigger_reload() { - Kiri::getDi()->get(Logger::class)->warning('change reload'); + $this->logger->notice('change reload'); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); From 57b22144335137b653cc78f324c88f11a4a2cfa9 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:03:01 +0800 Subject: [PATCH 34/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index d86c45fb..981284fc 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -139,6 +139,7 @@ class HotReload extends Command } + /** * 重启 * From 9800024d597aad0c4728c52658f683c94c3d3697 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:04:36 +0800 Subject: [PATCH 35/41] 1 --- kiri-engine/FileListen/HotReload.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 981284fc..57ae2825 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -97,9 +97,12 @@ class HotReload extends Command #[NoReturn] public function onSignal($data) { $this->driver->clear(); + $this->stop(); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { while (Process::kill($pid, 0)) { + var_dump($pid); + sleep(1); Process::kill($pid, SIGTERM); } } From 9ec6573ca4d1ad05731fe5777bef4cc9392b946f Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:04:44 +0800 Subject: [PATCH 36/41] 1 --- kiri-engine/FileListen/HotReload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 57ae2825..ce63ab89 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -97,7 +97,6 @@ class HotReload extends Command #[NoReturn] public function onSignal($data) { $this->driver->clear(); - $this->stop(); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { while (Process::kill($pid, 0)) { From c5c1d991f2866908ff278ed1d7911f9ce5008c0f Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:08:16 +0800 Subject: [PATCH 37/41] 1 --- kiri-engine/FileListen/HotReload.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index ce63ab89..7b996299 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -99,12 +99,13 @@ class HotReload extends Command $this->driver->clear(); $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); while (Process::kill($pid, 0)) { - var_dump($pid); sleep(1); Process::kill($pid, SIGTERM); } } + $this->stop(); $this->logger->notice('over'); } From fe4f9853151c9fa20dacb0c890ad196ebe072a0c Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:09:28 +0800 Subject: [PATCH 38/41] 1 --- kiri-engine/FileListen/HotReload.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 7b996299..e3ffd93f 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -100,10 +100,7 @@ class HotReload extends Command $pid = file_get_contents(storage('.swoole.pid')); if (!empty($pid) && Process::kill($pid, 0)) { Process::kill($pid, SIGTERM); - while (Process::kill($pid, 0)) { - sleep(1); - Process::kill($pid, SIGTERM); - } + Process::wait(TRUE); } $this->stop(); $this->logger->notice('over'); From 1d846a49035660769ebb3ced1b5d9e770ebc604d Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:10:41 +0800 Subject: [PATCH 39/41] 1 --- kiri-engine/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/Application.php b/kiri-engine/Application.php index 789ac5a4..2d62d120 100644 --- a/kiri-engine/Application.php +++ b/kiri-engine/Application.php @@ -223,6 +223,7 @@ class Application extends BaseApplication } + /** * @throws NotFindClassException * @throws ReflectionException From 84d8dda8eb0828cd673f7f9172acbdfab474c86e Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:10:55 +0800 Subject: [PATCH 40/41] 1 --- kiri-engine/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/Application.php b/kiri-engine/Application.php index 2d62d120..80dbf6b3 100644 --- a/kiri-engine/Application.php +++ b/kiri-engine/Application.php @@ -241,6 +241,7 @@ class Application extends BaseApplication } + /** * @param $className * @param null $abstracts From d9451f5087f1c980ab535c1a9d701492db419976 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 19 Nov 2021 04:11:29 +0800 Subject: [PATCH 41/41] 1 --- kiri-engine/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kiri-engine/Application.php b/kiri-engine/Application.php index 80dbf6b3..70fb32be 100644 --- a/kiri-engine/Application.php +++ b/kiri-engine/Application.php @@ -242,6 +242,7 @@ class Application extends BaseApplication + /** * @param $className * @param null $abstracts