This commit is contained in:
2020-09-01 15:51:34 +08:00
parent dae8325024
commit d21d5ede91
2 changed files with 6 additions and 3 deletions
-1
View File
@@ -23,7 +23,6 @@ class ServerManager
{ {
try { try {
$application = Snowflake::get(); $application = Snowflake::get();
$application->set(Pool::class, $pool);
if (is_string($process) && class_exists($process)) { if (is_string($process) && class_exists($process)) {
return static::createProcess($process, $application, $pool, $workerId); return static::createProcess($process, $application, $pool, $workerId);
} }
+6 -2
View File
@@ -27,8 +27,12 @@ class Processes extends Component
*/ */
public function initCore() public function initCore()
{ {
$server = new Pool($this->size(), SWOOLE_IPC_UNIXSOCK); $application = Snowflake::get();
$server->on('workerStart', function (Pool $pool, int $workerId) { $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); ServerManager::create($pool, $this->processes[$workerId], $workerId);
}); });
$server->on('workerStop', function (Pool $pool, int $workerId) { $server->on('workerStop', function (Pool $pool, int $workerId) {