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) {