PHP executes a code segment intermittently

Source: Internet
Author: User
How does PHP set to automatically execute a code segment at intervals? For example, to regularly generate static files, you need to set the sleep time, that is, the program will call a certain piece of code every time.

How does PHP set to automatically execute a code segment at intervals? For example, to regularly generate static files, you need to set the sleep time, that is, the program will call a certain piece of code every time.

The code is as follows:

  1. Ignore_user_abort (); // The PHP script can be executed even if the Client is disconnected (such as the browser is disabled.
  2. Set_time_limit (0); // the execution time is unlimited. the default php execution time is 30 seconds, so that the program can be executed without limit.
  3. $ Interval = 24*60*60; // run every other day
  4. Do {
  5. Sleep ($ interval); // wait for one hour to run cyclically according to the set time
  6. $ SQL = "update blog set time = now ()";
  7. Other operations
  8. } While (true );

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.