$filekey =config/php200.php; // 配置文件
if(file_exists($filekey)){
$crontab_num = 0;
do{
$mkeyall = include $filekey;
$mkey = $mkeyall['crontab_state'];
if ($mkey=="true"){ // 如果工作
/ 工作区间 //
$times = time();
$crontabinfo = $this->crontab_db->select(array('ifstop'=>0));
foreach($crontabinfo as $_k=>$rs) {
$run = 0;
if($rs[minutetime]){ //每隔几分钟执行一次
if($times-$rs[lasttime]>$rs[minutetime]*60){
$run++;
}
}elseif($rs[daytime]){ //每天执行一次,时+分格式如 1403
if(date("md",$rs[lasttime])!=date("md",$times)){
if(date("Hi",$times)>$rs[daytime]){
$run++;
}
}elseif(date("md",$rs[lasttime])==date("md",$times)){
if(date("Hi",$rs[lasttime])
$run++;
}
}
}elseif($rs[whiletime]){ //未来某个时间的,只执行一次
if($rs[lasttime]$rs[whiletime]){
$run++;
}
}
if($run){
$this->crontab_db->update(array('lasttime'=>$times),array('id'=>$rs[id]));
if($rs['filetype'] == 0){
$iframe = APP_PATH."crontabapi.php?op=".$rs['filepath']."&crontab_key=".$mkeyall['crontab_key']."&pc_hash=".$pc_hash;
}else{
$iframe = APP_PATH.$rs['filepath']."&crontab_key=".$mkeyall['crontab_key']."&pc_hash=".$pc_hash;
}
unset($run,$times,$rs,$crontabinfo);
file_get_contents($iframe);
/*$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $iframe);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILETIME, true);
curl_exec($ch);
curl_close($ch);*/
//sleep($interval);
}
}
$crontab_num++;
$setting[crontab_num] = $crontab_num;
$setting[crontab_time] = time();
setcache('crontab', $setting,'crontab');
/ 工作区间 //
}elseif ($mkey=="die"){ // 如果退出
die("退出工作");
}elseif ($mkey=="false"){ // 如果退出
echo("任务已停止,并未退出任务");
}else{ // 如果退出
die("无效配置参数");
}
sleep($interval); //休息50秒执行一次
}while(true);
?>