PHP计划任务的一种实现方法
如果由页面执行,设置
<?php
ignore_user_abort(true);
set_time_limit(0);
?>
运用sleep(300)+死循环,
这样就可以实现计划任务了,这个程序里不要有输出,有输出容易中断
现在正在运行的代码,已经一个小时了,没有问题,正在运行中,我通过页面运行的,
今天晚上我把它放到服务器上去,看看能运行几天
[php]
<?php
ignore_user_abort(true);
set_time_limit(0);
while(1){
$fp = fopen('time_task.txt',"a+");
$str = date("Y-m-d h:i:s")."\n";
fwrite($fp,$str);
fclose($fp);
sleep(1800); //半小时执行一次
}
?>
[/php]
[ 本帖最后由 unspace 于 2007-2-1 01:10 PM 编辑 ] |