HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

time_nanosleep

Description

The time_nanosleep of Miscellaneous for PHP delay for a number of seconds and nanoseconds.

Syntax

time_nanosleep ( int $seconds , int $nanoseconds ) : mixed

Parameters

seconds

Must be a non-negative integer.

nanoseconds

Must be a non-negative integer less than 1 billion.

Note: On Windows, the system may sleep longer that the given number of nanoseconds, depending on the hardware.

Return

Returns TRUE on success or FALSE on failure.

If the delay was interrupted by a signal, an associative array will be returned with the components:

secondsnumber of seconds remaining in the delay
nanosecondsnumber of nanoseconds remaining in the delay

Examples

1

<?

// won't work as expected if an array is returned
if (time_nanosleep(0, 500000000)) {
    echo "slept 0.5 seconds\n";
}

// better
if (time_nanosleep(0, 500000000) === true) {
    echo "slept 0.5 seconds\n";
}

// best
$sleep = time_nanosleep(0, 500000000);
if ($sleep === true) {
    echo "slept 0.5 seconds\n";
} elseif ($sleep === false) {
    echo "sleep failed\n";
} elseif (is_array($sleep)) {
    $seconds = $sleep['seconds'];
    $nanoseconds = $sleep['nanoseconds'];
    echo "interrupted by signal\n";
    echo "time remaining: $seconds seconds and $nanoseconds nanoseconds";
}
slept 0.5 seconds
slept 0.5 seconds
slept 0.5 seconds