This commit is contained in:
2021-11-04 16:18:02 +08:00
parent c0f404c497
commit 49b38a859c
3 changed files with 30 additions and 25 deletions
+3 -3
View File
@@ -116,10 +116,10 @@ class Application extends BaseApplication
*/ */
public function withFileChangeListen() public function withFileChangeListen()
{ {
$manager = $this->getServer(); $container = Kiri::getDi();
$manager->addProcess(FileChangeCustomProcess::class);
enable_file_modification_listening(); $console = $container->get(ConsoleApplication::class);
$console->add($container->get(FileChangeCustomProcess::class));
} }
@@ -5,15 +5,18 @@ namespace Kiri\FileListen;
use Exception; use Exception;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Kiri; use Kiri\Kiri;
use ReflectionException; use Swoole\Coroutine\Barrier;
use Server\Abstracts\BaseProcess;
use Swoole\Process; 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. $this->setName('sw:wather')
return 'file change listener.'; ->setDescription('server start|stop|reload|restart')
->addArgument('action', InputArgument::REQUIRED);
} }
@@ -40,7 +43,7 @@ class FileChangeCustomProcess extends BaseProcess
* @param Process $process * @param Process $process
* @throws Exception * @throws Exception
*/ */
public function onHandler(Process $process): void public function execute(InputInterface $input, OutputInterface $output): int
{ {
// TODO: Implement onHandler() method. // TODO: Implement onHandler() method.
set_error_handler([$this, 'onErrorHandler']); set_error_handler([$this, 'onErrorHandler']);
@@ -50,16 +53,15 @@ class FileChangeCustomProcess extends BaseProcess
} else { } else {
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
} }
$driver->start(); $make = Barrier::make();
} go(function () {
$this->trigger_reload();
});
/** go(function () use ($driver) {
* @param Process $process $driver->start();
*/ });
public function signListen(Process $process): void Barrier::wait($make);
{ return 0;
} }
@@ -85,10 +87,12 @@ class FileChangeCustomProcess extends BaseProcess
*/ */
public function trigger_reload() 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); // exec(PHP_BINARY . ' ' . APP_PATH . 'kiri.php runtime:builder', $output);
// //
// print_r(implode(PHP_EOL, $output)); // print_r(implode(PHP_EOL, $output));
Kiri::reload(); // Kiri::reload();
} }
} }
+3 -2
View File
@@ -3,7 +3,6 @@
namespace Kiri\FileListen; namespace Kiri\FileListen;
use Exception; use Exception;
use Swoole\Timer;
class Scaner class Scaner
{ {
@@ -129,7 +128,9 @@ class Scaner
$this->loadDirs(true); $this->loadDirs(true);
Timer::after(2000, [$this, 'tick']); sleep(2);
$this->tick();
} }
} }