Home  >  Article  >  Backend Development  >  How to execute code at intervals in PHP_PHP Tutorial

How to execute code at intervals in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:371034browse

How PHP executes code at intervals

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/950335.htmlTechArticleHow PHP executes code at intervals. 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 each PHP...
Statement:
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