sleep
Pauses the program for a number of seconds.
Syntax
sleep(int $seconds): intParameters
| Parameter | Type | Description |
|---|---|---|
| $seconds | int | How many seconds to wait. |
Return value
int`0` on success.
Examples
Retrying with a pause:
<?php
// retry.php
for ($attempt = 1; $attempt <= 3; $attempt++) {
echo "Attempt $attempt\n";
sleep(1);
}Notes
For pauses shorter than a second there is usleep(), which takes microseconds. On a site a pause delays the visitor's response, so pauses are used mostly in command-line scripts.
See also
In the tutorial
- Command-line scripts — PHP in the terminal — running a script, argv arguments, reading input, exit codes, getopt and running on a schedule.