Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-12 15:07:40 +08:00
parent 667d311d73
commit 367e1cd122
4 changed files with 404 additions and 404 deletions
+3 -3
View File
@@ -23,9 +23,9 @@ use Swoole\WebSocket\Server;
defined('DB_ERROR_BUSY') or define('DB_ERROR_BUSY', 'The database is busy. Please try again later.'); defined('DB_ERROR_BUSY') or define('DB_ERROR_BUSY', 'The database is busy. Please try again later.');
defined('SELECT_IS_NULL') or define('SELECT_IS_NULL', 'Query data does not exist, please check the relevant conditions.'); defined('SELECT_IS_NULL') or define('SELECT_IS_NULL', 'Query data does not exist, please check the relevant conditions.');
defined('PARAMS_IS_NULL') or define('PARAMS_IS_NULL', 'Required items cannot be empty, please add.'); defined('PARAMS_IS_NULL') or define('PARAMS_IS_NULL', 'Required items cannot be empty, please add.');
defined('CONTROLLER_PATH') or define('CONTROLLER_PATH', APP_PATH . 'controllers/'); defined('CONTROLLER_PATH') or define('CONTROLLER_PATH', realpath(APP_PATH . 'controllers/'));
defined('MODEL_PATH') or define('MODEL_PATH', APP_PATH . 'models/'); defined('MODEL_PATH') or define('MODEL_PATH', realpath(APP_PATH . 'models/'));
defined('COMPONENT_PATH') or define('COMPONENT_PATH', APP_PATH . 'components/'); defined('COMPONENT_PATH') or define('COMPONENT_PATH', realpath(APP_PATH . 'components/'));
/** /**
+10 -9
View File
@@ -3,18 +3,17 @@
namespace Kiri\FileListen; namespace Kiri\FileListen;
use Exception; use Exception;
use Kiri;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Annotation\Inject;
use Kiri\Core\Json; use Kiri\Core\Json;
use Kiri\Error\Logger; use Kiri\Error\Logger;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri;
use Kiri\Annotation\Inject;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Process; use Swoole\Process;
use Swoole\Timer; use Swoole\Timer;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -61,7 +60,6 @@ class HotReload extends Command
/** /**
* @throws ConfigException * @throws ConfigException
* @throws \ReflectionException
* @throws Exception * @throws Exception
*/ */
protected function initCore() protected function initCore()
@@ -198,27 +196,30 @@ class HotReload extends Command
} }
/** /**
* 重启 * 重启
* *
* @throws Exception * @throws Exception
*/ */
public function trigger_reload() public function trigger_reload(string $path = '')
{ {
if ($this->int == 1) { if ($this->int == 1) {
return; return;
} }
$this->int = 1; $this->int = 1;
$this->logger->warning('change reload'); $this->logger->warning('change reload');
if (!empty($path) && str_starts_with($path, CONTROLLER_PATH)) {
$pid = file_get_contents(storage('.swoole.pid'));
if (!empty($pid) && Process::kill($pid, 0)) {
Process::kill($pid, SIGUSR1);
}
} else {
$this->stopServer(); $this->stopServer();
$this->process = new Process(function (Process $process) { $this->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(); $this->process->start();
$this->int = -1; }
} }
+3 -7
View File
@@ -86,7 +86,7 @@ class Inotify
} }
//非重启类型 //非重启类型
if (str_ends_with($ev['name'], '.php')) { if (str_ends_with($ev['name'], '.php')) {
Timer::after(3000, fn() => $this->reload()); Timer::after(3000, fn() => $this->reload($ev['name']));
$this->isReloading = TRUE; $this->isReloading = TRUE;
} }
} }
@@ -95,9 +95,9 @@ class Inotify
/** /**
* @throws Exception * @throws Exception
*/ */
public function reload() public function reload($path)
{ {
$this->process->trigger_reload(); $this->process->trigger_reload($path);
$this->clearWatch(); $this->clearWatch();
foreach ($this->dirs as $root) { foreach ($this->dirs as $root) {
$this->watch($root); $this->watch($root);
@@ -113,11 +113,7 @@ class Inotify
public function clearWatch() public function clearWatch()
{ {
foreach ($this->watchFiles as $wd) { foreach ($this->watchFiles as $wd) {
try {
@inotify_rm_watch($this->inotify, $wd); @inotify_rm_watch($this->inotify, $wd);
} catch (\Throwable $exception) {
// logger()->addError($exception->getMessage(), 'throwable');
}
} }
$this->watchFiles = []; $this->watchFiles = [];
} }
+6 -3
View File
@@ -106,15 +106,18 @@ class Scaner
/** /**
* @throws Exception * @throws Exception
*/ */
public function timerReload() public function timerReload($path)
{ {
$this->isReloading = TRUE; $this->isReloading = TRUE;
$this->process->trigger_reload();
$this->process->int = -1; if (str_contains($path, CONTROLLER_PATH))
$this->process->trigger_reload($path);
$this->loadDirs(); $this->loadDirs();
$this->process->int = -1;
$this->isReloading = FALSE; $this->isReloading = FALSE;
$this->process->isReloadingOut = FALSE; $this->process->isReloadingOut = FALSE;