Swoole\Coroutine\System::sleep(float $seconds = -1)

Declaration

<?php
Swoole\Coroutine\System::sleep(float $seconds = -1)

Parameters

seconds

The duration of sleep.

Return

Description

Alias: Swoole\Coroutine::sleep.

Sleep in coroutine and release the CPU to other operations in the process.

Notice: sleep() in PHP should not be used within a coroutine context, because it is blocking the execution of the process. You should use co::sleep() instead.

Example

<?php
$server = new Swoole\Http\Server("127.0.0.1", 9502);

$server->on('request', function($request, $response) {
    Co\System::sleep(0.2);
    $response->end("<h1>Hello Swoole!</h1>");
});

$server->start();