How to use sleep() Function In PHP
The sleep() function pauses the execution of the script for a specified number of seconds. we are going to use that function for showing the time delaying between the printing the lines on the screen.
Example: This example shows the use of sleep() function for time delay.
<?php
echo "Start\n";
sleep(1); // Pauses script execution for 1 seconds
echo "End\n";
?>
Output:
Start
End
How to Set Time Delay in PHP ?
To set a time delay in PHP, you have several approaches depending on your requirements. The time delay is useful for various purposes like creating a pause in script execution or scheduling tasks.
These are the following different approaches:
Table of Content
- Using sleep() Function
- Using usleep() Function
- Using while loop
- Using DateTime() Object