Swoole\Process\Manager->addbatch

Latest version: pecl install openswoole-4.11.1

Declaration

<?php Swoole\Process\Manager->addBatch (int $workerNum, callable $func, bool $enableCoroutine = false)

Parameters

workerNum

How many processes to start to execute the function.

func

The function to be executed in the process.

enableCoroutine

If enable coroutine support within the process

Return

Description

Add multiple worker process to execute the function.

Example

<?php
$pm = new Swoole\Process\Manager();
$atomic = new Atomic(0);
$pm->addBatch(1, function (Pool $pool, int $workerId) use ($atomic) {
    usleep(100000);
    $atomic->wakeup();
});
$pm->add(function (Pool $pool, int $workerId) use ($atomic) {
    $atomic->wait(1.5);
    $pool->shutdown();
});
$pm->start();
Last updated on March 31, 2022