Home  >  Article  >  Backend Development  >  php简单定时执行任务的实现方法_PHP

php简单定时执行任务的实现方法_PHP

WBOY
WBOYOriginal
2016-05-31 13:16:54725browse

本文实例讲述了php简单定时执行任务的实现方法。分享给大家供大家参考。具体实现方法如下:

<&#63;php
ignore_user_abort();
set_time_limit(0);
$interval = 60*5;
do{
 $url = "http://www.sina.com.cn/";
 $ch = curl_init();//创建一个新的curl会话
 curl_setopt($ch,CURLOPT,$url);//设置需要抓取的cURL
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 //设置cURL参数,要求结果保存到字符串还是页面(1或真表示保存而不输出)
 curl_setopt($ch,CURLOPT_TIMEOUT,2);//最大延续2秒
 $result = curl_exec($ch);//执行
 curl_close($ch);//关闭
 sleep($interval);//休息5分钟
}while(true);
&#63;>

希望本文所述对大家的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