PHP Delay Program Execution using sleep() Example

Nov 17, 2022

.

Admin

PHP Delay Program Execution using sleep() Example

Hi Dev,

In this example, you will learn php delay program execution using sleep() example. it's simple example of php delay the program execution for the specified number of seconds. it's simple example of using sleep to add delay or increase execution time. I’m going to show you about sleep function in php with code examples.

In this example The sleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds, so Let's see following example with output.

Example :


index.php

<?php

// current time

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

//sleep for 5 seconds

sleep(5);

//start again

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

?>

Output:

10:49:00 First is current time

10:49:05 Second time is sleep for 5 seconds

I hope it could help you...

#PHP