近期需要开发一套站点服务器监控系统,现在网上收集下相关资料,为后期开发做好提前准备
相关函数代码
function httpcode($url){
$ch = curl_init();
$timeout = 3;
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
return $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
}调用方法:
$http_code = httpcode('http://www.baidu.com');//要监控的网站网址
if ($http_code != 200) {
echo ("网站出错,管理员正在赶来的路上……");
}- 标签
- php
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://sulao.cn/post/463
评论列表