Does PHP have a function to perform in a few seconds?

Source: Internet
Author: User
Does PHP have a function to perform in a few seconds interval?
For example, there is a piece of code that executes the first line, then the second line after 5 seconds.

Note that it is not a loop, it is executing code from top to bottom, and it takes a few seconds to pause in the middle.

------Solution--------------------
Sleep (5);
------Solution--------------------
Sleep (5) program pauses for 5 seconds
------Solution--------------------
The previous 1 is in the server's output buffer, or your browser's Z setup problem. But anyway, you wait for at least 5 seconds before you see the output!
PHP Code
Echo Microtime (); Current timestamp sleep (5); echo "
"; Echo Microtime ();
------Solution--------------------
Browser-related reasons, debugging with the CLI you can clearly see the effect of the pause
If only for this pause display effect, instead of to the front-end JS to deal with, if the program is placed in the background to run, you have to believe: two lines of the middle must have paused for 5 seconds
------Solution--------------------
Explore

There seems to be something wrong.

PHP Code
echo ' 1 ';
Sleep (5);
Echo '
5 ';


Each refresh appears to be 1 and 5 at the same time.

------Solution--------------------
Once every 5 seconds, how many times do you need to total?
If it is an infinite loop, then the shell or cron is used to control PHP execution. Generally PHP script execution time is best not more than 60 seconds. Otherwise, the script may get stuck.
------Solution--------------------
Sleep (5)
------Solution--------------------
Echo Microtime (); Current time stamp
Flush ();
Sleep (5);
echo "
";
Echo Microtime ();

So you can see the effect in the browser.
------Solution--------------------
Meaningless work, not saying that all the code upstairs is a problem, even if the code is completely no problem, and only in the specific text server with a specific browser is disabled to achieve

All people (including fools) think that the internet is too slow now. There are people who deliberately slow down the response of the network.

------Solution--------------------
PHP is mainly used to generate Web pages, the page is always generated and then sent to the browser, it is not possible to transmit 1.1 points, or a byte at a time, how many pages will pass over? Just set PHP to cmd command-line and CGI to achieve arbitrary pauses and intermittent displays like desktop programs
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.