From 916ca4b4db99bf62abb24a7cf1530c547fa2ded6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 7 Sep 2021 15:24:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-server/Server.php | 2 -- http-server/ServerCommand.php | 11 ++++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/http-server/Server.php b/http-server/Server.php index b2bc4840..1e1d2038 100644 --- a/http-server/Server.php +++ b/http-server/Server.php @@ -13,7 +13,6 @@ use Kiri\Events\EventDispatch; use Kiri\Exception\ConfigException; use Kiri\Rpc\RpcProvider; use Server\Events\OnShutdown; -use Swoole\Runtime; defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid'); @@ -82,7 +81,6 @@ class Server extends HttpService foreach ($processes as $process) { $this->manager->addProcess($process); } -// Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION); return $this->manager->getServer()->start(); } diff --git a/http-server/ServerCommand.php b/http-server/ServerCommand.php index b785954c..2e58ba63 100644 --- a/http-server/ServerCommand.php +++ b/http-server/ServerCommand.php @@ -6,14 +6,14 @@ namespace Server; use Annotation\Inject; use Exception; +use Kiri\Abstracts\Config; use Kiri\Events\EventProvider; -use Kiri\Exception\NotFindClassException; use Kiri\Kiri; -use ReflectionException; use Server\Events\OnBeforeWorkerStart; use Server\Events\OnWorkerStart; use Server\Worker\OnServerWorker; use Server\Worker\OnWorkerStart as WorkerDispatch; +use Swoole\Runtime; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -70,6 +70,10 @@ class ServerCommand extends Command if ($input->getArgument('action') == 'stop') { throw new Exception('shutdown success'); } + $enable_coroutine = Config::get('servers.settings.enable_coroutine', false); + if ($enable_coroutine === true) { + Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION); + } $this->generate_runtime_builder($manager); } catch (\Throwable $throwable) { $output->write($throwable->getMessage()); @@ -81,9 +85,6 @@ class ServerCommand extends Command /** * @param $manager - * @return void - * @throws NotFindClassException - * @throws ReflectionException */ private function generate_runtime_builder($manager): void {