Swoole Coroutine System: sleep

Notice: ext-swoole is supported until v4.7.1, use ext-openswoole >= v4.7.1. Latest version: pecl install openswoole-4.9.1


Swoole\Coroutine\System::sleep(float $seconds): void



The duration to sleep for. The value is a float, so 2.5 means 2.5 seconds. Minimum precision is 0.001 and the maximum is no more than one day which is 86400 seconds.


Returns true when successful and false when not.


Enter a sleep state within a coroutine and release the CPU to do other operations in the process. This is a non-blocking operation, the coroutine yields so that other coroutines can do work until the sleep has finished.

Note: The native PHP sleep() function should not be used within a coroutine context without coroutine hooks. However, if you have enabled coroutine hooks the recommended approach is to then only use the native sleep function. Checkout the sleep hook for more information, this allows you to use native PHP functions inside coroutines.



$server = new Swoole\Http\Server("", 9502);

$server->on('Request', function($request, $response)
    $response->end("<h1>Hello, from Swoole!</h1>");