How to use sleep and usleep function in PHP

PHP tutorial, explained to use sleep and usleep function in PHP. Sleep is very common method in every language. How sleep function works we need to understand.

use sleep and usleep function in PHP

Sleep function delays the program execution for the given number of seconds.
Usleep delays program execution for the given number of micro seconds.

Following is the php example with sleep function

<?php
echo date('h:i:s') . "<br />";

//stop execution for 30 seconds
sleep(30);

//start again
echo date('h:i:s');

?>

Following is the php example with usleep function

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
echo date('h:i:s') . &quot;&lt;br /&gt;&quot;;

//stop execution for 30 seconds
usleep(30000000);

//start again
echo date('h:i:s');
?>
How to use sleep and usleep function in PHP

How to use sleep and usleep function in PHP

Add a Comment

Your email address will not be published. Required fields are marked *