From 480e87d70bcea7880f8d867bbb215dfbdc41a2db Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Sun, 28 Feb 2021 14:29:38 +0800 Subject: [PATCH] modify --- HttpServer/Events/OnWorkerStart.php | 31 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 0a72e8b5..7a0bb3b5 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -37,9 +37,9 @@ class OnWorkerStart extends Callback public function onHandler(Server $server, int $worker_id): void { $container['enable_deadlock_check'] = false; - $container['exit_condition'] = function () { - return Co::stats()['coroutine_num'] === 0; - }; +// $container['exit_condition'] = function () { +// return Co::stats()['coroutine_num'] === 0; +// }; Coroutine::set($container); $get_name = $this->get_process_name($server, $worker_id); @@ -47,7 +47,7 @@ class OnWorkerStart extends Callback swoole_set_process_name($get_name); } -// $this->onSignal($server, $worker_id); + $this->onSignal($server, $worker_id); if ($worker_id >= $server->setting['worker_num']) { fire(Event::SERVER_TASK_START); @@ -64,18 +64,17 @@ class OnWorkerStart extends Callback * @param $server * @param $worker_id */ -// public function onSignal($server, $worker_id) -// { -// $this->debug(sprintf(workerName($worker_id) . ' #%d is start.....', $worker_id)); -// Coroutine\go(function (Server $server, $worker_id) { -// Coroutine::waitSignal($this->signal); -// while (Co::stats()['coroutine_num'] > 0) { -// var_dump(Co::stats()['coroutine_num']); -// Coroutine::sleep(1); -// } -// return $server->stop($worker_id, true); -// }, $server, $worker_id); -// } + public function onSignal($server, $worker_id) + { + $this->debug(sprintf(workerName($worker_id) . ' #%d is start.....', $worker_id)); + Coroutine\go(function (Server $server, $worker_id) { + Coroutine::waitSignal($this->signal); + while (Snowflake::app()->isRun()) { + Coroutine::sleep(1); + } + return $server->stop($worker_id, true); + }, $server, $worker_id); + } /**