PHP code execution method at intervals

Source: Internet
Author: User
This article mainly introduces the PHP method for executing code at intervals, which can automatically execute a code at intervals. it is a very practical technique, for more information about how to run PHP code at intervals, see the example in this article. Share it with you for your reference. The specific analysis is as follows:

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:

The code is as follows:

Ignore_user_abort (); // The PHP script can be executed even if the Client is disconnected (such as the browser is disabled.
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.
$ Interval = 24*60*60; // run every other day
Do {
Sleep ($ interval); // wait for one hour to run cyclically according to the set time
$ SQL = "update blog set time = now ()";
Other operations
} While (true );

I hope this article will help you with PHP programming.

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.