Swoole Hook Sleep

Notice: the documentation is suitable for PHP extension swoole until v4.7.1, we only support PHP extension openswoole from v4.7.1

The SWOOLE_HOOK_SLEEP flag will enable coroutine support for blocking sleep PHP functions. Support was added in v4.2.0.

This includes support for:

  • sleep
  • usleep
  • time_nanosleep
  • time_sleep_until

Example

<?php

Co::set(['hook_flags' => SWOOLE_HOOK_SLEEP]);

Co\run(function()
{
    go(function()
    {
        sleep(1);
        echo '1' . PHP_EOL;
    });

    go(function()
    {
        echo '2' . PHP_EOL;
    });
});