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:
- 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 );