搜索
首页php教程php手册站点监控php代码(多站点的话稍加修改就行),可手机短信报警

站点监控php代码(多站点的话稍加修改就行),可手机短信报警

Jun 13, 2016 am 10:43 AM
htmlphp下面代码修改手机短信报警新建格式监控站点

下面html格式代码,你新建一个hostmonter.php的文件,然后将下面的代码复制到文件中并保存,上传到服务器上,然后用浏览器也可以用Linux的定时器等工具进行,下在的代码是每10分钟检查一次,下面的代码中有三个域名,多个域名自行修改一下:

—————————————–代码内容————————————




function check($host, $find)
{
    $fp = fsockopen($host, 80, $errno, $errstr, 10);
    if (!$fp)
    {
        echo “$errstr ($errno)\n”;
    } else
    {
       $header = “GET / HTTP/1.1\r\n”;
       $header .= “Host: $host\r\n”;
       $header .= “Connection: close\r\n\r\n”;
       fputs($fp, $header);
       while (!feof($fp))
       {
           $str .= fgets($fp, 1024);
       }
       fclose($fp);
       return (strpos($str, $find) !== false);
    }
}
function ok($host)
{
    /* 下面的youremail@139.com改成你的邮箱地址 */
    /*  mail(’200513538@qq.com’, ‘Monitoring’, $host.’ down’);  */
    echo “$host – OK
”;
}

function posttohost($host)
{
    /* 下面是以西部数码短信接口为例 */
        $maildomain=’域名’;
 $mailpwd=’密码’;
 $sendmobile=’接收报警的手机号,联通/电信189/移动都可以’;
 $sendcontent=”$host 出现故障!”;
 $sendport=’3′;
 if($maildomain!=”"){
  $key=md5($maildomain.$mailpwd);
  $url=”http://usericp.west263.cn/default.aspx“;
  $data=array(‘mobile’=>$sendmobile,’sendcontent’=>mb_convert_encoding($sendcontent, “UTF-8″, “gb2312″),’port’=>$sendport,’maildomain’=>$maildomain,’key’=>$key);
  $data=http_build_query($data);
  $opts=array(‘http’=>array(‘method’=>’POST’,
          ‘header’=>”Content-type: application/x-www-form-urlencoded\r\n”.
          “Content-Length:”.strlen($data).”\r\n”,
          ‘content’=>$data),);
  $context=stream_context_create($opts);
  $html=file_get_contents($url,false,$context); 
  $result=iconv(“UTF-8″,”gb2312″,$html);
  if($result==”200 ok”){
     echo “$host – sendOK
”;
   }else{
    echo “$result
”;
   }
 
 
 }
}
for ($i=1; $i {
   if ($i==1)
      {
        /* 下面的网址改成你要监控的网址 */
        $host = ‘www.xxx.com’;
  $Content = “www.xxx.com-无法连接”;
       }elseif ($i==2)
      {
        $host = ‘www.yyy.com’;
  $Content = “www.yyy.com-无法连接”;
      }elseif ($i==3)
      {
        $host = ‘www.zzz.com’;
  $Content = “www.zzz.com-无法连接”;
       }

/* 下面的”备案号:”改成你的网站首页源代码中的一段特殊字符串 */
$find = ‘备案号:’;

if (!check($host, $find))
 {
  posttohost($host);
 }
else
 {ok($host);}

}
?>


——————————————代码结束———————————————

 from:lonely blog

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用