php实现计划任务主要使用了 ignore_user_abort() set_time_limit(0) sleep() 这三个函数
<?<span class='wp_keywordlink'><a href="http://seo0395.om" title="php" target="_blank">php</a></span>
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.<span class='wp_keywordlink'><a href="http://seo0395.om" title="php" target="_blank">php</a></span>';//引入文件
$curl=new httpCurl('www.<span class='wp_keywordlink'><a href="http://seo0395.om" title="php" target="_blank">php</a></span>ernote.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);//程序执行时间
具体的实现过程中个人感觉PHP定时执行任务的效率并不高,建议关于定时执行任务的工作还是交给shell来做吧,相对来说,这个方法实现的太过勉强,而shell是专业级别的了。