Process Pool

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Manage a pool of Linux worker processes with Swoole. It can be used to manage a group of worker processes to process messages in MQ like Redis or sent from client side. Native Linux commands can also be executed by the pool of processes.

When a process in the pool is terminated, the pool starts a replacement process automatically.





$workerNum = 10;
$pool = new OpenSwoole\Process\Pool($workerNum);

$pool->on("WorkerStart", function ($pool, $workerId) {
    echo "Worker#{$workerId} is started\n";
    $redis = new Redis();
    $redis->pconnect('', 6379);
    $key = "key1";
    while (true) {
         $msgs = $redis->brpop($key, 2);
         if ( $msgs == null) continue;

$pool->on("WorkerStop", function ($pool, $workerId) {
    echo "Worker#{$workerId} is stopped\n";

Last updated on September 1, 2022