Use the sleep function in PHP to implement the code of the scheduled execution function.
In some quiz websites, if we need to implement a regular execution function, such as a question, it will be completed within 10 seconds; otherwise, "you have timed out" will be displayed, then I jumped to the next question, and there was a 10-second pause in the middle. How was this function implemented?
In PHP, there is a sleep function, which probably means that when a program runs a sleep function, it is paused for N seconds and continues to be executed. For example, sleep (10) means that the program runs from top to bottom. When the sleep (10) Statement is run, it is paused for 10 seconds and then continues to run. The parameter in the function brackets is a numerical value, indicating the pause time value, in seconds. See the following code:
<? Php // current timeecho date ('H: I: s'). "\ n"; // sleep for 10 secondssleep (10); // wake up! Echo date ('H: I: s'). "\ n";?>
The execution result of the above program is:
05:31:23
05:31:33
Some children's shoes may say how to execute an error when making an instance, prompting timeout. Don't be alarmed when this problem occurs. This is caused by the default page execution time of PHP. in PHP, the default page execution time is thirty seconds, which is enough for general programs. However, if you want to perform a scheduled execution function like this, you must declare the execution time in the header and set set_time_limit (0 ). 0 indicates the time limit, in seconds.
If the execution time exceeds 30 seconds, you must connect to MYSQL again before performing the operation. Otherwise, the execution is invalid !!! The reason is that the database connection may be disconnected after the execution time is too long, so the database information cannot be read!
Click here to add a pause function for your instance, and then execute it.