From 2bf341d23d0c28dce022abea0f4021c9db7bfab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 4 Mar 2021 10:50:05 +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 --- HttpServer/Events/OnWorkerStart.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 833d6f30..0f108baf 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -40,12 +40,11 @@ class OnWorkerStart extends Callback annotation()->read(APP_PATH . 'app', 'App'); $this->debug(sprintf('scan app dir use time %s', microtime(true) - $start)); - $prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid); if ($worker_id >= $server->setting['worker_num']) { - $this->onTask($server, $worker_id, $prefix); + $this->onTask($server, $worker_id); } else { - $this->onWorker($server, $worker_id, $prefix); + $this->onWorker($server, $worker_id); } } @@ -57,10 +56,12 @@ class OnWorkerStart extends Callback * @throws ComponentException * @throws ConfigException */ - public function onTask(Server $server, int $worker_id, $prefix) + public function onTask(Server $server, int $worker_id) { putenv('environmental=' . Snowflake::TASK); + $prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid); + $start = microtime(true); fire(Event::SERVER_TASK_START); @@ -78,10 +79,13 @@ class OnWorkerStart extends Callback * @throws ConfigException * @throws Exception */ - public function onWorker(Server $server, int $worker_id, $prefix) + public function onWorker(Server $server, int $worker_id) { Snowflake::setWorkerId($server->worker_pid); putenv('environmental=' . Snowflake::WORKER); + + $prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid); + try { $start = microtime(true); fire(Event::SERVER_WORKER_START, [$worker_id]);