In some of the website of quiz, if we need to do a function of timed execution, for example, a problem, in 10 seconds to complete, otherwise show "You have timed out", if completed, then jump to the next question above, and this middle has a 10-second pause, such a function is how to achieve it?
In PHP, there is a sleep function, presumably meaning that the program execution encounters the sleep function while pausing for n seconds before continuing. Sleep (10) means that the program is executed from the top down, the sleep (10) statement is paused for 10 seconds, and then the execution continues. The parameter in the function parentheses is a numeric value that represents the pause time, in seconds. Take a look at the following code:
<?php
//Current time
echo date (' H:i:s '). "\ n";
Sleep for ten seconds Sleep
(a);
Wake Up!
echo Date (' H:i:s '). "\ n";
? >
The results of the above program execution are:
05:31:23
05:31:33
may be some child shoes to do when the example will say how my program execution error, prompt timeout. This problem does not panic, this is the PHP default page execution time, in PHP, the default execution page time is 30 seconds, which is sufficient for general procedures. But if you want to do a function like timed execution, you must Set_time_limit (0) The execution time of the head declaration setting. 0 is the limit when the unit is seconds.
If the execution time exceeds 30 seconds, then perform the operation remember to connect MySQL again, otherwise invalid execution!!! The reason is that after too long execution time, the database connection may be disconnected, and you cannot read the database information!
To do it, add a pause function to your instance, and then proceed down.