PHP自动Get监控网站是否在线,创建个PHP文件放到你的网站根目录里面,访问后不会出现结果,等待个20秒左右关闭页面,就会自动执行了。
如果不重启php服务器 或者重启服务器,get监控一直会处于运行状态。
<?php //设置脚本运行不超时 set_time_limit(0); //即使浏览器关闭还继续运营 ignore_user_abort(true); //睡眠5秒 sleep(5); //要监控的网址 $cronurl = 'https://www.baidu.com/'; //开始get监控 httpGet($cronurl); //这里还可以无限添加httpGet("网址"); //获取当前文件的访问url $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //开始get运行,达到无限循环的效果 httpGet($url); //发起GET模拟请求 function httpGet($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Encoding: gzip, deflate')); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $output = curl_exec($ch); curl_close($ch); return $output; }