PHP定时执行任务的实现

时间:2014-08-07 12:51:09   收藏:0   阅读:217

转自:http://www.topthink.com/topic/2945.html

 1 <?php
 2 ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.
 3 set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
 4 $interval=60*30;// 每隔半小时运行
 5 
 6 do{
 7 $fp= fopen("t4554.txt", "w");
 8 if($fp) { 
 9     $count=0; 
10     for($i=1;$i<=4;$i++){ 
11         $flag=fwrite($fp,"行".$i." : "."Hello World!\r\n"); 
12         if(!$flag){
13             echo"写入文件失败<br>";break;         
14         }
15         $count+=$flag; 
16     } 
17 }
18 fclose($fp);
19     //这里是你要执行的代码   
20     sleep(‘2‘);// 等待5分钟
21 }while(true);
22 ?> 

 

PHP定时执行任务的实现,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!