暴力采集5秒,然后停止,休息2分钟,然后暴力采集5秒,一直循环下去。
<!--?php
$type=(int)$_GET['type'];
$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['Status']==1){
echo "--任务开启1";
echo '<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">