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 {