monitor(); } public function monitor() { #统计一定时间区间内的uv频率 $startTime = strtotime(date('Y-m-d 09:00:00',time())); $endTime = strtotime(date('Y-m-d 17:00:00',time())); $currentTime = time(); if($startTime > $currentTime || $endTime < $currentTime || (date('w',$currentTime)==6) || (date('w',$currentTime) == 0)){ return false; } $fiveMinuteBefore = date('Y-m-d H:i:s',strtotime('-5 minutes')); $pv = DB::table('templates_log')->where('create_time','<=',date('Y-m-d H:i:s',$currentTime))->where('create_time','>=',$fiveMinuteBefore)->count(); if($pv <= 1){ #发送验证码报警 self::sendMsg('13161864516'); self::sendMsg('18410900527'); error_log(date('Y-m-d H:i:s',time()).' pv:'.$pv." \n ",3,"/log/seafood_log/script_success/".date('Y-m-d',time()).'Monitor.log'); } } private static function init(){ $ch = curl_init(); /* 设置验证方式 */ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8')); /* 设置返回结果为流 */ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); /* 设置超时时间*/ curl_setopt($ch, CURLOPT_TIMEOUT, 10); /* 设置通信方式 */ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); return $ch; } public static function sendMsg($phone){ $tpl_id = YP_TPL_ID; $ch=self::init(); //$data=array('tpl_id' => $tpl_id,'text'=>$text,'apikey'=>YP_SMS_KEY,'mobile'=>$phone); $data = [ 'apikey' => YP_SMS_KEY, 'mobile' => $phone, 'tpl_id' => $tpl_id, ]; $json_data = self::tpl_send($ch,$data); //print_r($json_data); ******************************maybe影响验证码发出 $array = json_decode($json_data,true); // echo '
';print_r($array); curl_close($ch); return $array; } private static function tpl_send($ch,$data){ curl_setopt ($ch, CURLOPT_URL, YP_TPL_URL); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $result = curl_exec($ch); $error = curl_error($ch); self::checkErr($result,$error); return $result; } private static function checkErr($result,$error) { if($result === false) { echo 'Curl error: ' . $error; } // else // { // echo '操作完成没有任何错误'; // } } }