nexus-runtime-swoole
Swoole 5.0+ coroutine runtime for Nexus — true async I/O, native channels, and multi-process scaling.
What's in this package
SwooleRuntime— implementsRuntime; wrapsCo\run()and usesSwoole\Coroutine::create()for actor spawningSwooleConfig—maxCoroutines,defaultMailboxCapacity,enableCoroutineHook; all fieldsreadonlySwooleMailbox— backed bySwoole\Coroutine\Channel; native coroutine suspension ondequeueBlocking()SwooleCancellable— wraps a Swoole timer ID;cancel()callsSwoole\Timer::clear()DeferredCancellable— internal handle for timers scheduled beforeCo\run()starts
Install
composer require nexus-actors/runtime-swoole
Quick example
src/bootstrap.php
use Monadial\Nexus\Core\Actor\ActorSystem;
use Monadial\Nexus\Core\Actor\Behavior;
use Monadial\Nexus\Core\Actor\Props;
use Monadial\Nexus\Runtime\Swoole\SwooleConfig;
use Monadial\Nexus\Runtime\Swoole\SwooleRuntime;
$runtime = new SwooleRuntime(new SwooleConfig(maxCoroutines: 50_000));
$system = ActorSystem::create('app', $runtime);
$system->spawn(Props::fromBehavior(Behavior::receive(
static fn($ctx, $msg): Behavior => Behavior::same(),
)), 'worker');
$system->run(); // enters Co\run(), blocks until all coroutines finish
run() enters Co\run(), which blocks until all coroutines and timers complete. For HTTP/WebSocket deployments, pass a SwooleRuntime to the server runner via nexus-http-server-swoole or nexus-http-server-swoole-threads.
See also
- nexus-runtime —
Runtimeinterface,Duration, and mailbox contracts - nexus-runtime-fiber — fiber runtime for development
- nexus-http-server-swoole — Swoole HTTP server runner