diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 766fe4a4..2d81c478 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -34,6 +34,8 @@ class OnWorkerStart extends Callback if (!empty($get_name) && !Snowflake::isMac()) { swoole_set_process_name($get_name); } + + putenv('workerId=' . $worker_id); if ($worker_id >= $server->setting['worker_num']) { fire(Event::SERVER_TASK_START); return; @@ -65,7 +67,7 @@ class OnWorkerStart extends Callback */ private function get_process_name($socket, $worker_id): string { - $prefix = rtrim(Config::get('id',false, 'system:'), ':'); + $prefix = rtrim(Config::get('id', false, 'system:'), ':'); if ($worker_id >= $socket->setting['worker_num']) { return $prefix . ': Task: No.' . $worker_id; } else { diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index 42f43e53..39d58ea5 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -108,6 +108,9 @@ abstract class Pool extends Component */ public function createConnect(array $config, string $coroutineName, callable $createHandler): void { + if ($this->size($coroutineName) > 0) { + return; + } if (Context::hasContext('create:connect:' . $coroutineName)) { return; } diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index 89ae4a76..3bb9d8ca 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -235,7 +235,7 @@ class Connection extends Pool if (!empty($charset)) { $link->query('SET NAMES ' . $charset); } - $this->success('create db client -> ' . $cds . ':' . $this->hasCreate[$coroutineName] . ':' . $this->size($coroutineName)); + $this->success('create db client -> ' . $cds . ':' . env('workerId', 0)); $this->incr($coroutineName); if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) { $number > 0 && $link->beginTransaction(); diff --git a/System/Pool/Redis.php b/System/Pool/Redis.php index 41ee7946..da6ed9db 100644 --- a/System/Pool/Redis.php +++ b/System/Pool/Redis.php @@ -78,7 +78,7 @@ class Redis extends Pool if (empty($config['auth']) || !$redis->auth($config['auth'])) { throw new RedisConnectException(sprintf('Redis Error: %s, Host %s, Auth %s', $redis->getLastError(), $config['host'], $config['auth'])); } - $this->success('create redis client -> ' . $config['host'] . ':' . $this->size($coroutineName)); + $this->success('create redis client -> ' . $config['host'] . ':' . env('workerId', 0)); if (!isset($config['read_timeout'])) { $config['read_timeout'] = 10; }