php原生方法监控服务&网站的运行情况,原理很简单,就是获取网页的头部文件,正确时候返回的头部文件是有信息的!利用这个来判断服务是否正常运行!
header('content-type:text/html;charset=utf-8');
set_time_limit(0);
error_reporting(E_WARNING);
$radius=array(
'106.187.11.128'=>array('url'=>'http://www.daimago.com','urlbefore'=>'https://www.daimago.com/index?a=1'),
);
function pings($ip,$time) {
exec('ping -n 1 -w '.$time.' '.$ip,$list);
$errorlog=$list[2];
$encode = mb_detect_encoding($errorlog, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
//echo $encode;
$str_encode = mb_convert_encoding($errorlog, 'UTF-8', $encode);
/*echo $str_encode;*/
if('请求超时。' === $str_encode){
return $ip;
}else{
return false;
}
}