Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Core\Process\Manager->addBatch (int $workerNum, callable $func, bool $enableCoroutine = false)
How many processes to start to execute the function.
The function to be executed in the process.
If enable coroutine support within the process
Add multiple processes to execute the same function.
You have to install OpenSwoole core library with
composer require openswoole/core
to use this feature.
<?php
$pm = new OpenSwoole\Core\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();