Swoole Coroutine System: sleep

4.x is outdated, please check the latest version 22.x

Latest version: pecl install openswoole-22.1.2


<?php Swoole\Coroutine\System::sleep(int $seconds): void



The duration to sleep for. The value is a int, so 2 means 2 seconds. No more than one day which is 86400 seconds.


Returns true when successful and false when not.


Since Open Swoole v4.10.0 the data type of $seconds is fixed inline with PHP

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>");

Last updated on August 31, 2022