From 49b38a859c883ed72d7663ad1a4cea14f57a6e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 4 Nov 2021 16:18:02 +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 --- kiri-engine/Application.php | 6 +-- .../FileListen/FileChangeCustomProcess.php | 44 ++++++++++--------- kiri-engine/FileListen/Scaner.php | 5 ++- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/kiri-engine/Application.php b/kiri-engine/Application.php index d8115d40..d8407170 100644 --- a/kiri-engine/Application.php +++ b/kiri-engine/Application.php @@ -116,10 +116,10 @@ class Application extends BaseApplication */ public function withFileChangeListen() { - $manager = $this->getServer(); - $manager->addProcess(FileChangeCustomProcess::class); + $container = Kiri::getDi(); - enable_file_modification_listening(); + $console = $container->get(ConsoleApplication::class); + $console->add($container->get(FileChangeCustomProcess::class)); } diff --git a/kiri-engine/FileListen/FileChangeCustomProcess.php b/kiri-engine/FileListen/FileChangeCustomProcess.php index 2c199216..33fb2bcb 100644 --- a/kiri-engine/FileListen/FileChangeCustomProcess.php +++ b/kiri-engine/FileListen/FileChangeCustomProcess.php @@ -5,15 +5,18 @@ namespace Kiri\FileListen; use Exception; use Kiri\Abstracts\Config; use Kiri\Kiri; -use ReflectionException; -use Server\Abstracts\BaseProcess; +use Swoole\Coroutine\Barrier; use Swoole\Process; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; /** * */ -class FileChangeCustomProcess extends BaseProcess +class FileChangeCustomProcess extends Command { @@ -26,13 +29,13 @@ class FileChangeCustomProcess extends BaseProcess /** - * @param Process $process - * @return string + * */ - public function getProcessName(Process $process): string + protected function configure() { - // TODO: Implement getProcessName() method. - return 'file change listener.'; + $this->setName('sw:wather') + ->setDescription('server start|stop|reload|restart') + ->addArgument('action', InputArgument::REQUIRED); } @@ -40,7 +43,7 @@ class FileChangeCustomProcess extends BaseProcess * @param Process $process * @throws Exception */ - public function onHandler(Process $process): void + public function execute(InputInterface $input, OutputInterface $output): int { // TODO: Implement onHandler() method. set_error_handler([$this, 'onErrorHandler']); @@ -50,16 +53,15 @@ class FileChangeCustomProcess extends BaseProcess } else { $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); } - $driver->start(); - } - - - /** - * @param Process $process - */ - public function signListen(Process $process): void - { - + $make = Barrier::make(); + go(function () { + $this->trigger_reload(); + }); + go(function () use ($driver) { + $driver->start(); + }); + Barrier::wait($make); + return 0; } @@ -85,10 +87,12 @@ class FileChangeCustomProcess extends BaseProcess */ public function trigger_reload() { + proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $pipes); + // exec(PHP_BINARY . ' ' . APP_PATH . 'kiri.php runtime:builder', $output); // // print_r(implode(PHP_EOL, $output)); - Kiri::reload(); +// Kiri::reload(); } } diff --git a/kiri-engine/FileListen/Scaner.php b/kiri-engine/FileListen/Scaner.php index c325b92d..4cb48c5a 100644 --- a/kiri-engine/FileListen/Scaner.php +++ b/kiri-engine/FileListen/Scaner.php @@ -3,7 +3,6 @@ namespace Kiri\FileListen; use Exception; -use Swoole\Timer; class Scaner { @@ -129,7 +128,9 @@ class Scaner $this->loadDirs(true); - Timer::after(2000, [$this, 'tick']); + sleep(2); + + $this->tick(); } }