Sleep Function in PHP

Sleep function will execute some part of code after a defined period of time (in PHP, in seconds).

In PHP, we can use it with some date operations, but it’s not always useful since it doesn’t automatically render the part of a code that is placed before sleep(). We need to wait extra seconds for everything, not only for that delayed part.

If you expect another behavior, check Sleep Function in JavaScript.

If you, however, want to use PHP for this, here’s how:



echo date('h:i:s');

// sleep for 2 seconds
echo '<br>';

// show new time

echo date('h:i:s');