-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add options to listen to swoole server events
- Loading branch information
1 parent
995f141
commit 8eb882d
Showing
11 changed files
with
168 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Runtime\Swoole; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Swoole\Server; | ||
|
||
trait SwooleEventsTrait | ||
{ | ||
private function registerSwooleEvents(Server $server, array $options, ?ContainerInterface $container = null): void | ||
{ | ||
if (!array_key_exists('server_event_listener_factory', $options)) { | ||
return; | ||
} | ||
|
||
$eventListener = $options['server_event_listener_factory']($container); | ||
if (!$eventListener instanceof SwooleServerEventListenerInterface) { | ||
return; | ||
} | ||
|
||
$server->on('start', [$eventListener, 'onStart']); | ||
$server->on('workerStart', [$eventListener, 'onWorkerStart']); | ||
$server->on('workerStop', [$eventListener, 'onWorkerStop']); | ||
$server->on('workerError', [$eventListener, 'onWorkerError']); | ||
$server->on('workerExit', [$eventListener, 'onWorkerExit']); | ||
$server->on('task', [$eventListener, 'onTask']); | ||
$server->on('finish', [$eventListener, 'onFinish']); | ||
$server->on('shutdown', [$eventListener, 'onShutdown']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Runtime\Swoole; | ||
|
||
use Swoole\Server; | ||
|
||
interface SwooleServerEventListenerInterface | ||
{ | ||
public function onStart(Server $server): void; | ||
public function onShutdown(Server $server): void; | ||
public function onWorkerStart(Server $server, int $workerId): void; | ||
public function onWorkerStop(Server $server, int $workerId): void; | ||
public function onWorkerError(Server $server, int $workerId, int $exitCode, int $signal): void; | ||
public function onWorkerExit(Server $server, int $workerId): void; | ||
public function onTask(Server $server, int $taskId, int $srcWorkerId, mixed $data): void; | ||
public function onFinish(Server $server, int $taskId, $data): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters