Join 4,000+ others and never miss out on new tips, tutorials, and more.
25.x is outdated, please check the latest version 26.x
Latest version:
pecl install openswoole-26.2.0
<?php OpenSwoole\Core\Coroutine\WaitGroup->add(int $count = 1)
Increment the WaitGroup counter by the value.
if success, it returns TRUE, otherwise it returns FALSE.
Increment the WaitGroup counter, by default increment it by 1.
You have to install OpenSwoole core library with
composer require openswoole/coreto use this feature.
<?php
declare(strict_types=1);
use OpenSwoole\Core\Coroutine\WaitGroup;
co::run(function() {
$wg = new WaitGroup();
go(function () use ($wg) {
$wg->add();
co::usleep(300000);
$wg->done();
});
go(function () use ($wg) {
$wg->add();
co::usleep(700000);
$wg->done();
});
$wg->wait(1);
});