nexus-worker-pool-swoole
Swoole thread primitives for the worker pool: Thread\Queue transport, Thread\Map directory, and the WorkerPool DSL for zero-boilerplate pool setup.
What's in this package
WorkerPool— fluent builder:withThreads,actor,stateful,behavior,configure,onStart,runWorkerPoolApp— class-based alternative; extend and overrideconfigure(WorkerNode $node)WorkerPoolBootstrap— lower-level bootstrap viaSwoole\Thread\Pool; used internally byWorkerPoolandWorkerPoolAppWorkerPoolHandle— main-thread handle passed toonStart;workerCount(),queues(),directory(),stop()ThreadQueueTransport—WorkerTransportbacked by oneSwoole\Thread\Queueper worker; adaptive-poll backoff coroutine loopThreadMapDirectory—WorkerDirectorybacked by a sharedSwoole\Thread\MapWorkerRunnable—Swoole\Thread\Runnablethread entrypoint; used internally
Requirements
- PHP 8.5+ with ZTS (verify:
php -r 'echo PHP_ZTS;'must print1) - Swoole 6.0+ compiled with
--enable-swoole-thread
Install
composer require nexus-actors/worker-pool-swoole
Quick example
src/Worker/boot.php
use Monadial\Nexus\WorkerPool\Swoole\WorkerPool;
use Monadial\Nexus\WorkerPool\Swoole\WorkerPoolHandle;
WorkerPool::withThreads(8)
->withName('shop')
->actor('orders', OrderActor::class)
->actor('payments', PaymentActor::class)
->configure(static function (\Monadial\Nexus\WorkerPool\WorkerNode $node): void {
$node->log()->info('Worker ready', ['id' => $node->workerId()]);
})
->onStart(function (WorkerPoolHandle $handle): void {
echo 'Workers ready: ' . $handle->workerCount() . PHP_EOL;
})
->run();
Closures passed to behavior(), configure(), and withLoggerFactory() must be static with no object captures — they are serialized via opis/closure before crossing thread boundaries.
See also
- nexus-worker-pool —
WorkerNode,ConsistentHashRing,WorkerActorRef, and transport/directory interfaces - Scaling / overview — topology guide
- Scaling / bootstrap — full wiring examples