Home  >  Article  >  Backend Development  >  Implementation of PHP scheduled tasks_PHP tutorial

Implementation of PHP scheduled tasks_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:021075browse

Recently, because the project needs to do some processing on the remote database regularly, we need to make something like a scheduled task here. After hard work, I finally implemented this planned task using PHP. Let’s share the implementation process this time.

This time using PHP to implement scheduled tasks mainly uses the three functions ignore_user_abort() set_time_limit(0) sleep().

The specific code is as follows:

<?php
ignore_user_abort();//该函数的作用是当用户关掉浏览器后,PHP脚本也可以继续执行.
set_time_limit(3000);// 通过set_time_limit(0)可以让程序无限制的执行下去
$interval=5;// 每隔5s运行
//方法1--死循环
do{
	echo '测试'.time().'<br/>'; 
	sleep($interval);// 等待5s    
}while(true);
//方法2---sleep 定时执行
require_once './curlClass.php';//引入文件
$curl=new httpCurl('www.phpernote.com');//实例化
$stime=$curl->getmicrotime();
for($i=0;$i<=10;$i++){
	echo '测试'.time().'<br/>'; 
	sleep($interval);// 等待5s
}
ob_flush();
flush();
$etime=$curl->getmicrotime();
echo '<hr>';
echo round(($etime-stime),4);//程序执行时间

In the specific implementation process, I personally feel that the efficiency of PHP's scheduled task execution is not high. It is recommended that the work of scheduled task execution be left to the shell. Relatively speaking, this method is too reluctant to implement, and the shell It's professional level.

Articles you may be interested in

  • Win7 scheduled task settings
  • php counts the number of people online, an accurate way to count the number of people online
  • PHP records the origin of the search engine and the keywords entered in the search
  • The safest and most realistic solution for PHP to determine the uploaded file type
  • What is the PHP design pattern and how to understand it
  • PHP analyzes the file header information to determine the type of uploaded file
  • php gets the last day of any month
  • The underlying operating mechanism and principle of PHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/779407.htmlTechArticleRecently, because the project needs to do some processing on the remote database regularly, we need to make something like a scheduled task here. . After hard work, I finally realized this scheduled task using 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