From 7ab08af442d1036d502436598fc769f27107ecbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 23 Jul 2021 10:48:18 +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 --- Server/Worker/ServerWorker.php | 24 ++++++++++++++++++++---- function.php | 14 +++++++------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Server/Worker/ServerWorker.php b/Server/Worker/ServerWorker.php index 127eee70..b43b7e6e 100644 --- a/Server/Worker/ServerWorker.php +++ b/Server/Worker/ServerWorker.php @@ -2,6 +2,7 @@ namespace Server\Worker; +use Annotation\Annotation; use Exception; use Server\Constant; use Snowflake\Abstracts\Config; @@ -33,19 +34,34 @@ class ServerWorker extends \Server\Abstracts\Server $annotation = Snowflake::app()->getAnnotation(); $annotation->read(APP_PATH . 'app'); - debug(sprintf('Worker[%d]#%03d start.', $server->worker_pid, $workerId)); - $this->runEvent(Constant::WORKER_START, null, [$server, $workerId]); + + $this->workerInitExecutor($server, $annotation, $workerId); + } + + + /** + * @param Server $server + * @param Annotation $annotation + * @param int $workerId + * @throws ConfigException + * @throws Exception + */ + private function workerInitExecutor(Server $server, Annotation $annotation, int $workerId) + { if ($workerId < $server->setting['worker_num']) { $loader = Snowflake::app()->getRouter(); $loader->_loader(); - $this->setProcessName(sprintf('Worker #%03d[%d]', $server->worker_pid, $workerId)); + echo sprintf('Worker[%d].#%03d start.', $server->worker_pid, $workerId) . PHP_EOL; + $this->setProcessName(sprintf('Worker[%d].#%03d', $workerId, $server->worker_pid)); $annotation->runtime(CONTROLLER_PATH); $annotation->runtime(MODEL_PATH); } else { - $this->setProcessName(sprintf('Tasker #%03d[%d]', $server->worker_pid, $workerId)); + echo sprintf('Tasker[%d].#%03d start.', $server->worker_pid, $workerId) . PHP_EOL; + + $this->setProcessName(sprintf('Tasker[%d].#%03d', $workerId, $server->worker_pid)); $annotation->runtime(APP_PATH, [CONTROLLER_PATH]); } diff --git a/function.php b/function.php index f04e0109..937ce057 100644 --- a/function.php +++ b/function.php @@ -886,7 +886,7 @@ if (!function_exists('swoole_substr_json_decode')) { * @param int $length * @return mixed */ - function swoole_substr_json_decode($packet, $length = 0): mixed + function swoole_substr_json_decode($packet, int $length = 0): mixed { return json_decode($packet, true); } @@ -901,7 +901,7 @@ if (!function_exists('swoole_substr_unserialize')) { * @param int $length * @return mixed */ - function swoole_substr_unserialize($packet, $length = 0): mixed + function swoole_substr_unserialize($packet, int $length = 0): mixed { return unserialize($packet); } @@ -912,7 +912,7 @@ if (!function_exists('swoole_substr_unserialize')) { if (!function_exists('debug')) { /** - * @param $message + * @param mixed $message * @param string $method * @throws Exception */ @@ -926,11 +926,11 @@ if (!function_exists('debug')) { if (!function_exists('error')) { /** - * @param $message + * @param mixed $message * @param string $method * @throws Exception */ - function error(mixed $message, $method = 'error') + function error(mixed $message, string $method = 'error') { Snowflake::app()->error($message, $method); } @@ -939,11 +939,11 @@ if (!function_exists('error')) { if (!function_exists('success')) { /** - * @param $message + * @param mixed $message * @param string $method * @throws Exception */ - function success(mixed $message, $method = 'app') + function success(mixed $message, string $method = 'app') { Snowflake::app()->success($message, $method); }