From d21d5ede91a85d877eba902fe77055f6a3f493fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 1 Sep 2020 15:51:34 +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 --- http-server/ServerManager.php | 1 - system/Processes.php | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/http-server/ServerManager.php b/http-server/ServerManager.php index c3bc5193..a1fb3be8 100644 --- a/http-server/ServerManager.php +++ b/http-server/ServerManager.php @@ -23,7 +23,6 @@ class ServerManager { try { $application = Snowflake::get(); - $application->set(Pool::class, $pool); if (is_string($process) && class_exists($process)) { return static::createProcess($process, $application, $pool, $workerId); } diff --git a/system/Processes.php b/system/Processes.php index 2384a951..bbf52cff 100644 --- a/system/Processes.php +++ b/system/Processes.php @@ -27,8 +27,12 @@ class Processes extends Component */ public function initCore() { - $server = new Pool($this->size(), SWOOLE_IPC_UNIXSOCK); - $server->on('workerStart', function (Pool $pool, int $workerId) { + $application = Snowflake::get(); + $server = $application->set(Pool::class, new Pool($this->size(), SWOOLE_IPC_UNIXSOCK)); + $server->on('workerStart', function (Pool $pool, int $workerId) use ($application) { + if (is_string($this->processes[$workerId]) && class_exists($this->processes[$workerId])) { + $application->set($this->processes[$workerId], $workerId); + } ServerManager::create($pool, $this->processes[$workerId], $workerId); }); $server->on('workerStop', function (Pool $pool, int $workerId) {