详情页

高铁采集器实现定时开启与定时结束的解决方法

时间:2023年10月14日

编辑:佚名

高铁采集实现定时任务,除了定时任务之外,官方内置了一个进程管理器,可以实现如下功能
暴力采集5秒,然后停止,休息2分钟,然后暴力采集5秒,一直循环下去。
<!--?php
$type=(int)$_GET[&#39;type&#39;];
$id=38;
$start="http://127.0.0.1:808/api?model=job&action=start&jobid=".$id;
$pause="http://127.0.0.1:808/api?model=job&action=pause&jobid=".$id;
$stop="http://127.0.0.1:808/api?model=job&action=stop&jobid=".$id;
//开始任务
$date=date("Y-m-d H:i:s");  
echo $date;
if($type<1){
     
  $data=postUrl("",$start,$data);
   
  $arr=json_decode($data,true);
  if($arr[&#39;Status&#39;]==1){
     echo "--任务开启1";
     echo &#39;<meta http-equiv="refresh" content="5;url=5.php?type=1"-->';
  }else{
      echo "-- 任务暂停1";
      echo '<meta http-equiv="refresh" content="125;url=5.php?type=0">';
       
  }
     
}else{
     
    $data=postUrl("",$pause,$data);
$arr=json_decode($data,true);
      if($arr['Status']==1){
        echo "-- 任务暂停2";
        echo '<meta http-equiv="refresh" content="125;url=5.php?type=0">';
      }else{
          echo "--任务开启2";
          echo '<meta http-equiv="refresh" content="5;url=5.php?type=1">';
           
      }
}
function postUrl($ref, $url, $postdata = '', $timeout = 30){
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $ref);
if (strpos('check_ssl' . $url, 'https') > 0) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
curl_setopt($ch, CURLOPT_POST, 1);
if ($postdata != '') {
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
} catch (Exception $ex) {
return 'Error: ' . $ex;
}
}
?></meta http-equiv="refresh" content="5;url=5.php?type=1"></meta http-equiv="refresh" content="125;url=5.php?type=0"></meta http-equiv="refresh" content="125;url=5.php?type=0">
相关文章
猜你需要