变更
This commit is contained in:
+15
-8
@@ -21,7 +21,7 @@ class HotReload extends Command
|
|||||||
/**
|
/**
|
||||||
* @var Process
|
* @var Process
|
||||||
*/
|
*/
|
||||||
private Process $process;
|
private ?Process $process;
|
||||||
/**
|
/**
|
||||||
* @var array|mixed
|
* @var array|mixed
|
||||||
*/
|
*/
|
||||||
@@ -38,7 +38,7 @@ class HotReload extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private array $dirs = [APP_PATH . 'app/', APP_PATH . 'config/', APP_PATH . 'router/'];
|
private array $dirs = [APP_PATH . 'app/', APP_PATH . 'config/', APP_PATH . 'routes/'];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,11 +50,15 @@ class HotReload extends Command
|
|||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$this->startProcess();
|
$this->startProcess();
|
||||||
|
pcntl_signal(SIGINT | SIGQUIT | SIGTERM, function () {
|
||||||
|
Process::wait();
|
||||||
|
});
|
||||||
if (extension_loaded('inotify')) {
|
if (extension_loaded('inotify')) {
|
||||||
$this->onInotifyReload();
|
$this->onInotifyReload();
|
||||||
} else {
|
} else {
|
||||||
$this->onCrontabReload();
|
$this->onCrontabReload();
|
||||||
}
|
}
|
||||||
|
Process::wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,10 +67,11 @@ class HotReload extends Command
|
|||||||
*/
|
*/
|
||||||
private function startProcess(): void
|
private function startProcess(): void
|
||||||
{
|
{
|
||||||
$this->process = new Process(function (Process $process) {
|
$process = new Process(function (Process $process) {
|
||||||
$process->exec(PHP_BINARY . ' ' . APP_PATH . 'kiri.php', ['sw:server', 'start']);
|
$process->exec(PHP_BINARY, [APP_PATH . 'kiri.php', 'sw:server', 'start']);
|
||||||
});
|
},);
|
||||||
$this->process->start();
|
$process->start();
|
||||||
|
$this->process = $process;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -266,7 +271,9 @@ class HotReload extends Command
|
|||||||
*/
|
*/
|
||||||
public function trigger_reload(): void
|
public function trigger_reload(): void
|
||||||
{
|
{
|
||||||
$this->process->exit(0);
|
echo 'tigger server Reload' . PHP_EOL;
|
||||||
|
Process::kill($this->process->pid, SIGTERM);
|
||||||
|
$this->process = null;
|
||||||
$this->startProcess();
|
$this->startProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +287,7 @@ class HotReload extends Command
|
|||||||
try {
|
try {
|
||||||
inotify_rm_watch($inotify, $wd);
|
inotify_rm_watch($inotify, $wd);
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
error($exception);
|
logger()->addError($exception, 'throwable');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->watchFiles = [];
|
$this->watchFiles = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user