From 02d0c9a8fdf61267a554fc8ec5d3dbe66ceb35e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 12 Jan 2022 14:43:28 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=94=B9=E5=90=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fdf58326 --- Handler/OnServerWorker.php | 4 +++- Server.php | 21 +++---------------- ServerCommand.php | 41 +------------------------------------- 3 files changed, 7 insertions(+), 59 deletions(-) diff --git a/Handler/OnServerWorker.php b/Handler/OnServerWorker.php index bb98361..ea6152c 100644 --- a/Handler/OnServerWorker.php +++ b/Handler/OnServerWorker.php @@ -3,11 +3,12 @@ namespace Kiri\Server\Handler; use Exception; +use Kiri; use Kiri\Abstracts\Config; use Kiri\Annotation\Inject; use Kiri\Core\Help; use Kiri\Events\EventDispatch; -use Kiri; +use Kiri\Message\Handler\Router; use Kiri\Server\Events\OnAfterWorkerStart; use Kiri\Server\Events\OnBeforeWorkerStart; use Kiri\Server\Events\OnTaskerStart as OnTaskStart; @@ -44,6 +45,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server $this->eventDispatch->dispatch(new OnBeforeWorkerStart($workerId)); set_env('environmental_workerId', $workerId); if ($workerId < $server->setting['worker_num']) { + Kiri::getContainer()->get(Router::class)->scan_build_route(); $this->eventDispatch->dispatch(new OnWorkerStart($server, $workerId)); $this->setProcessName(sprintf('Worker[%d].%d', $server->worker_pid, $workerId)); set_env('environmental', Kiri::WORKER); diff --git a/Server.php b/Server.php index 6ee2c40..0da2804 100644 --- a/Server.php +++ b/Server.php @@ -65,8 +65,10 @@ class Server extends HttpService * @throws \ReflectionException * @throws Exception */ - public function start(): string + public function start(): mixed { + $this->configure_set(); + $this->manager()->initBaseServer(Config::get('server', [], true), $this->daemon); $rpcService = Config::get('rpc', []); @@ -102,23 +104,6 @@ class Server extends HttpService } - /** - * @return void - * @throws ConfigException - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - * @throws \ReflectionException - * @throws \Exception - */ - public function runtime_start(): void - { - $this->configure_set(); - - $this->container->get(Router::class)->read_files(); - - $this->start(); - } - /** * @return void diff --git a/ServerCommand.php b/ServerCommand.php index a1b259c..2c1a552 100644 --- a/ServerCommand.php +++ b/ServerCommand.php @@ -77,46 +77,7 @@ class ServerCommand extends Command return 1; } } - $manager->runtime_start(); - return 0; - } - - - /** - * @throws ConfigException - */ - private function configure_set() - { - $enable_coroutine = Config::get('servers.settings.enable_coroutine', false); - Config::set('servers.settings.enable_coroutine', true); - if ($enable_coroutine != true) { - return; - } - Coroutine::set([ - 'hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION, - 'enable_deadlock_check' => FALSE, - 'exit_condition' => function () { - return Coroutine::stats()['coroutine_num'] === 0; - } - ]); - } - - - /** - * @param $manager - * @return int - * @throws ConfigException - * @throws Exception - */ - private function generate_runtime_builder($manager): int - { - $this->configure_set(); - - Kiri::app()->getRouter()->read_files(); - - $manager->start(); - - return 1; + return $manager->start(); } }