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
Execute your function with multiple processes managed by Openswoole process manager.
You can add multiple different tasks into a process manager and launch multiple copies of processes to execute the same task.
The current process stops and a new process will be started when the task is finished.
You have to install OpenSwoole core library with
composer require openswoole/core
to use this feature.
OpenSwoole\Core\Process\Manager::__construct
OpenSwoole\Core\Process\Manager->add
OpenSwoole\Core\Process\Manager->addBatch
OpenSwoole\Core\Process\Manager->setIPCType
OpenSwoole\Core\Process\Manager->getIPCType
OpenSwoole\Core\Process\Manager->setMsgQueueKey
OpenSwoole\Core\Process\Manager->getMsgQueueKey
OpenSwoole\Core\Process\Manager->start
<?php
$pm = new OpenSwoole\Core\Process\Manager();
$atomic = new Atomic(0);
$pm->add(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();