Compare commits

..

4 Commits

Author SHA1 Message Date
as2252258 3ca39d2205 eee 2026-07-03 14:25:26 +08:00
as2252258 908c8719d3 eee 2026-06-24 20:17:54 +08:00
as2252258 69b845d924 eee 2026-06-12 23:57:18 +08:00
as2252258 d9c8344a29 eee 2026-04-17 16:31:59 +08:00
4 changed files with 25 additions and 20 deletions
+2 -1
View File
@@ -2,6 +2,7 @@
namespace Kiri\Server\Abstracts; namespace Kiri\Server\Abstracts;
use Kiri\Di\HotReloadState;
use Kiri\Di\Inject\Container; use Kiri\Di\Inject\Container;
use Kiri\Error\StdoutLogger; use Kiri\Error\StdoutLogger;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
@@ -241,10 +242,10 @@ class FileWatcher extends AbstractProcess implements OnProcessInterface
$preview .= ' ...'; $preview .= ' ...';
} }
di(HotReloadState::class)->store($changedFiles);
di(StdoutLogger::class)->println('detected file changes, reloading server: ' . $preview); di(StdoutLogger::class)->println('detected file changes, reloading server: ' . $preview);
$server = di(ServerInterface::class); $server = di(ServerInterface::class);
var_dump($server::class, get_class_methods($server));
if (method_exists($server, 'reload')) { if (method_exists($server, 'reload')) {
$server->reload(); $server->reload();
} }
+1 -1
View File
@@ -74,7 +74,7 @@ class OnServerWorker extends Kiri\Server\Abstracts\Server
try { try {
$this->dispatch->dispatch(new OnBeforeWorkerStart($server, $workerId)); $this->dispatch->dispatch(new OnBeforeWorkerStart($server, $workerId));
if ($workerId < $server->setting['worker_num']) { if ($workerId < $server->setting['worker_num']) {
CoordinatorManager::utility(Coordinator::WORKER_START)->waite(); CoordinatorManager::utility(Coordinator::WORKER_START)->wait();
$this->dispatch->dispatch(new OnWorkerStart($server, $workerId)); $this->dispatch->dispatch(new OnWorkerStart($server, $workerId));
} else { } else {
+21 -17
View File
@@ -125,22 +125,26 @@ class ServerCommand extends Command
} }
/** /**
* @param InputInterface $input * @param InputInterface $input
* @return int * @return int
* @throws * @throws
*/ */
protected function start(InputInterface $input): int protected function start(InputInterface $input): int
{ {
$this->asyncServer->addProcess(config('process', [])); $this->asyncServer->addProcess(config('process', []));
if (\config('servers.reload.hot', false) === true) { $hotReload = \config('servers.reload.hot', false) === true;
$this->asyncServer->addProcess([FileWatcher::class]); if ($hotReload) {
} else { $this->asyncServer->addProcess([FileWatcher::class]);
di(Router::class)->scan_build_route(); }
} if (!$hotReload) {
$this->asyncServer->initCoreServers(config('servers.server', []), (int)$input->getOption('daemon')); // 非热更模式可在 Master 进程预扫描,Worker 通过 fork 继承扫描结果。
$this->asyncServer->start(); // 热更模式必须让新 Worker 自己加载业务类,避免继承旧类定义后无法重新声明。
return 1; di(Router::class)->scan_build_route();
} }
$this->asyncServer->initCoreServers(config('servers.server', []), (int)$input->getOption('daemon'));
$this->asyncServer->start();
return 1;
}
} }
+1 -1
View File
@@ -9,7 +9,7 @@
} }
], ],
"require": { "require": {
"php": ">=8.4", "php": ">=8.5",
"ext-json": "*", "ext-json": "*",
"composer-runtime-api": "^2.0", "composer-runtime-api": "^2.0",
"psr/http-server-middleware": "^1.0", "psr/http-server-middleware": "^1.0",