Skip to main content

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

Requirements

  • PHP 8.5+ with ZTS (verify: php -r 'echo PHP_ZTS;' must print 1)
  • 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