![]() |
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() FunctionThe 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.
Output: Start Using usleep() FunctionThe usleep() function pauses the execution in microseconds. 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 usleep() function for time delay.
Output Start End Using while loopUse a while loop with a time condition to create a delay. it will first print the line that is outside of the loop then after one second it will print the line inside the loop. Example: This example shows the implementation of the above-explained approach.
Output Start End Using DateTime() ObjectCreate a future timestamp and compare it to the current time. then create a loop that will execute after 1 second exactly. Example: This example shows the implementation of the above-explained approach.
Output: Start |
Reffered: https://www.geeksforgeeks.org
PHP |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |