usleep()

usleep() — Delay execution in microseconds.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Delays program execution for the given number of microseconds.

Signature

usleep(int $microseconds): void

Parameters

ParameterTypeWhat it takes
$microsecondsintHalt time in microseconds. A microsecond is one millionth of a second.

Return value

No value is returned.

Example

A runnable snippet:

// Current time echo (new DateTime('now'))->format('H:i:s.v'), "\n"; // wait for 2 milliseconds usleep(2000); // back! echo (new DateTime('now'))->format('H:i:s.v'), "\n"; // wait for 30 milliseconds usleep(30000); // back again! echo (new DateTime('now'))->format('H:i:s.v'), "\n";

Output:

11:13:28.005 11:13:28.007 11:13:28.037

See also

sleep(), time_nanosleep(), time_sleep_until(), set_time_limit()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page usleep() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.