变更
This commit is contained in:
+15
-11
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1, ticks=1);
|
||||||
|
|
||||||
namespace Kiri\Server;
|
namespace Kiri\Server;
|
||||||
|
|
||||||
@@ -28,6 +29,9 @@ class HotReload extends Command
|
|||||||
private array $watchFiles = [];
|
private array $watchFiles = [];
|
||||||
|
|
||||||
|
|
||||||
|
private bool $isExit = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -44,24 +48,19 @@ class HotReload extends Command
|
|||||||
/**
|
/**
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @param OutputInterface $output
|
* @param OutputInterface $output
|
||||||
* @return void
|
* @return int
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$this->startProcess();
|
$this->startProcess();
|
||||||
$bool = pcntl_signal(SIGINT | SIGQUIT | SIGTERM, function () {
|
sleep(3);
|
||||||
$this->stopProcess();
|
|
||||||
|
|
||||||
$pid = (int)file_get_contents(storage('.swoole.pid'));
|
|
||||||
pcntl_waitpid($pid, $status);
|
|
||||||
});
|
|
||||||
echo 'Listen signal ' . ($bool ? 'success' : 'fail') . PHP_EOL;
|
|
||||||
if (extension_loaded('inotify')) {
|
if (extension_loaded('inotify')) {
|
||||||
$this->onInotifyReload();
|
$this->onInotifyReload();
|
||||||
} else {
|
} else {
|
||||||
$this->onCrontabReload();
|
$this->onCrontabReload();
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,6 +147,11 @@ class HotReload extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pid = (int)file_get_contents(storage('.swoole.pid'));
|
||||||
|
if ($pid <= 0 || !Process::kill($pid, 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->loadDirs(true);
|
$this->loadDirs(true);
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
@@ -162,7 +166,7 @@ class HotReload extends Command
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function loadByDir($path, $isReload = false): void
|
private function loadByDir($path, bool $isReload = false): void
|
||||||
{
|
{
|
||||||
if (!is_string($path)) {
|
if (!is_string($path)) {
|
||||||
return;
|
return;
|
||||||
@@ -211,7 +215,7 @@ class HotReload extends Command
|
|||||||
/**
|
/**
|
||||||
* 开始监听
|
* 开始监听
|
||||||
*/
|
*/
|
||||||
public function check($inotify)
|
public function check($inotify): void
|
||||||
{
|
{
|
||||||
if (!($events = inotify_read($inotify))) {
|
if (!($events = inotify_read($inotify))) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user