Home >Backend Development >PHP Tutorial >How to execute code at intervals in PHP_PHP Tutorial
This example describes how PHP executes code at intervals. Share it with everyone for your reference. The specific analysis is as follows:
How to set up PHP to automatically execute a certain piece of code every period of time? For example, to generate static files regularly, this requires setting a sleep time, that is, the program will call a certain piece of code every once in a while.
The code is as follows:
Copy the code as follows:ignore_user_abort(); //Even if the Client is disconnected (such as closing the browser), the PHP script can continue to execute.
Set_time_limit(0); // The execution time is unlimited. The default execution time of PHP is 30 seconds, which allows the program to execute without limit.
$interval=24*60*60; // Run every other day
do{
sleep($interval); // Wait for one hour according to the set time and execute the loop
$sql="update blog set time=now()";
...... //Other operations
}while(true);
I hope this article will be helpful to everyone’s PHP programming design.