Home > Backend Development > PHP Tutorial > How to execute code in PHP at intervals, php interval_PHP tutorial

How to execute code in PHP at intervals, php interval_PHP tutorial

WBOY
Release: 2016-07-13 10:12:36
Original
1146 people have browsed it

PHP method to execute code at intervals, php interval

The example in this article 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 once in a while? For example, to generate static files regularly, you need to set the sleep time, that is, the program will call a certain piece of code every once in a while.

The code is as follows:

Copy code The code is 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 one hour for loop execution according to the set time
$sql="update blog set time=now()";
...... //Other operations
}while(true);

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920613.htmlTechArticleHow PHP executes code at intervals, php interval This article describes how PHP executes code at intervals. Share it with everyone for your reference. The specific analysis is as follows: PHP such as...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template