Does PHP have the function of executing the task several seconds later? For example, if there is a code segment, first execute the first line, and then execute the second line after 5 seconds. Note that, instead of a loop, the code is executed in the order from top to bottom, it takes several seconds to pause in the middle, sleep (5);, sleep (5) the program pauses for 5 seconds, and the previous 1 is output by the server. does PHP have the function of waiting several seconds for execution?
For example, if there is a code segment, first execute the first line, and then execute the second line after 5 seconds.
Note that the code is executed in the order from top to bottom, instead of a loop. the pause takes several seconds.
------ Solution --------------------
Sleep (5 );
------ Solution --------------------
Sleep (5) program pause for 5 seconds
------ Solution --------------------
The previous 1 is in the output cache of the server, or your browser z settings are incorrect. But in any case, you waited for at least five seconds to see the output!
PHP code
Echo microtime (); // Current timestamp sleep (5); echo"
"; Echo microtime ();
------ Solution --------------------
For browser reasons, you can see the effect of the pause when debugging with CLI.
If it is only for the display effect of the pause, it is better to hand over to the front-end js for processing. if the program is running in the background, you must believe that the middle of the two lines must have paused for 5 seconds.
------ Solution --------------------
Discussion
It seems a problem.
PHP code
Echo '1 ';
Sleep (5 );
Echo'
5 ';
Each refresh appears to be both 1 and 5.
------ Solution --------------------
How many times does it need to be executed every five seconds?
If it is an infinite loop, use SHELL or CRON to control the execution of PHP. Generally, PHP script execution time should not exceed 60 seconds. Otherwise, the script may be stuck.
------ Solution --------------------
Sleep (5)
------ Solution --------------------
Echo microtime (); // Current timestamp
Flush ();
Sleep (5 );
Echo"
";
Echo microtime ();
In this way, you will see the effect in the browser.
------ Solution --------------------
Meaningless work, not to mention that all the code above is problematic, even if there is no problem with the code, it can only be achieved by using a specific text server with a specific browser.
Everyone (including Dummies) thinks that the Internet is too slow. Some people intentionally slow down the network response speed.
------ Solution --------------------
PHP is mainly used to generate web pages. a web page is always generated once and then transmitted to the browser. it cannot be transmitted at. Otherwise, how many pages will be transmitted at one byte? Only by setting PHP as CMD command line and CGI can we achieve arbitrary pause and intermittent display of content like a desktop program