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
Since OpenSwoole v4.10.0 the data type of $seconds is fixed inline with PHP
The OpenSwoole\Runtime::HOOK_SLEEP
flag will enable coroutine support for blocking sleep PHP functions. Support was added in OpenSwoole v4.2.0
.
This includes support for:
sleep
usleep
time_nanosleep
time_sleep_until
<?php
Co::set(['hook_flags' => OpenSwoole\Runtime::HOOK_SLEEP]);
Co::run(function()
{
go(function()
{
sleep(1);
echo '1' . PHP_EOL;
});
go(function()
{
echo '2' . PHP_EOL;
});
});