PHP定时执行任务的实现

来源:互联网 发布:js如何把Date中的-去掉 编辑:程序博客网 时间:2024/05/11 11:14
config.php
<?php
return 1;
?>
cron.php
ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
$interval=60*30;// 每隔半小时运行
do{
$run = include 'config.php';
if(!$run) die('process abort');
//这里是你要执行的代码
sleep($interval);// 等待5分钟

}while(true);

主要改变config.php中return 0就可以实现了控制这个cron

0 0