后台以php示例,php后台运行的示例--非常经典

$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);

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值