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.