Site Monitoring php code (if multiple sites are used, you can modify the code slightly). You can send SMS alerts.

Source: Internet
Author: User

The following html code creates a hostmonter. php file, copy the following code to the file, save it, upload it to the server, and then use a browser or a Linux timer or other tools, the code below is checked every 10 minutes. The following code contains three domain names. Modify multiple domain names as needed:

-------------- Code content ------------

<Html>
<Body>
<Meta http-equiv = "refresh" content = "600">
<? Php
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 ";
Fputs ($ fp, $ header );
While (! Feof ($ fp ))
{
$ Str. = fgets ($ fp, 1024 );
}
Fclose ($ fp );
Return (strpos ($ str, $ find )! = False );
}
}
Function OK ($ host)
{
/* Change the following youremail@139.com to your email address */
/* Mail ('1970 @ qq.com ', 'monitoring', $ host. 'drop ');*/
Echo "$ host-OK <br> ";
}

Function posttohost ($ host)
{
/* The following uses the Western Digital text message interface as an example */
$ Maildomain = 'domain name ';
$ Mailpwd = 'Password ';
$ Sendmobile = 'mobile phone number for receiving alerts, which can be China Unicom/China Telecom 189/mobile ';
$ Sendcontent = "$ host fault !";
$ Sendport = '3 ′;
If ($ maildomain! = ""){
$ Key = md5 ($ maildomain. $ mailpwd );
$ Url = "http://usericp.west263.cn/default.aspx.pdf;
$ 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 <br> ";
} Else {
Echo "$ result <br> ";
}
 
 
}
}
For ($ I = 1; $ I <= 3; $ I ++)
{
If ($ I = 1)
{
/* Change the following URL to the URL you want to monitor */
$ Host = 'www .xxx.com ';
$ Content = "www.xxx.com-unable to connect ";
} Elseif ($ I = 2)
{
$ Host = 'www .yyy.com ';
$ Content = "www.yyy.com-unable to connect ";
} Elseif ($ I = 3)
{
$ Host = 'www .zzz.com ';
$ Content = "www.zzz.com-unable to connect ";
}

/* Change "record filing number:" to a special character string in the source code of your website homepage */
$ Find = 'filing No :';

If (! Check ($ host, $ find ))
{
Posttohost ($ host );
}
Else
{OK ($ host );}

}
?>

</Body>
<Html>

-------------- Code ended ---------------

From: lonely blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.