The PHP server status monitoring has not been done by many friends. Only when the website is suspended can we know that such a website is shut down in the middle of the night and is very bad for the website, next let's take a look at the server status monitoring program compiled by xiaobian. The PHP server status monitoring has not been done by many friends. Only when the website is suspended can we know that such a website is shut down in the middle of the night and is very bad for the website, next let's take a look at the server status monitoring program compiled by xiaobian.
Script ec (2); script
In the past two days, I took the time to write a web server status monitoring report. If someone says yes, I will release it. Very simple.
Usage
Open the status. php file in the compressed package. Edit the content here for your own mailbox information.
The Code is as follows: |
|
$ Mail-> Host = 'smtp .exmail.qq.com '; // smtp Server $ Mail-> Port = 25; // SMTP server Port number $ Mail-> Username = 'admin @ xxx.com '; // SMTP Server Username $ Mail-> Password = 'Password'; // SMTP server password $ Mail-> SetFrom ('admin @ xxx.com ', 'status '); $ Mail-> AddReplyTo ('admin @ xxx.com ', 'status '); $ Mail-> Subject = $ subject; $ Mail-> AltBody = 'To view the message, please use an HTML compatible email viewer! '; // Optional, comment out and test $ Mail-> MsgHTML ($ body ); $ Address = 'admin @ admin.com '; // receiving email address |
Change the content here to the IP address you want to monitor
The Code is as follows: |
|
$ Server_ip_list = array ( '61. 135.169.121 ', '1970. 204.173.200 ', '194.127.83' ); |
Visit your http://yourdomain.com/status.php file to view the current server status and automatically send the mail to your mailbox. If you need automatic monitoring, add a Cron task or use a monitoring site!
Complete code
The Code is as follows: |
|
/* * Server Status Monitoring */ Header ('content-type: text/html; charset = UTF-8 '); Include './smtp/class. smtp. php '; Include './smtp/class. phpmailer. php '; Function sendmail ($ subject = '', $ body = ''){ Date_default_timezone_set ('Asia/Shanghai'); // set the time zone UTC + 8. $ Mail = new PHPMailer (); // a new PHPMailer object is displayed. // $ Body = eregi_replace ("[]", '', $ body); // filter the email content. $ Mail-> CharSet = "UTF-8"; // set the mail encoding, the default ISO-8859-1, this must be set if you send Chinese, otherwise garbled $ Mail-> IsSMTP (); // you can specify the SMTP service. $ Mail-> SMTPAuth = true; // enable SMTP Verification $ Mail-> Host = 'smtp .exmail.qq.com '; // smtp Server $ Mail-> Port = 25; // SMTP server Port number $ Mail-> Username = 'admin @ xxx.com '; // SMTP Server Username $ Mail-> Password = 'Password'; // SMTP server password $ Mail-> SetFrom ('admin @ xxx.com ', 'status '); $ Mail-> AddReplyTo ('admin @ xxx.com ', 'status '); $ Mail-> Subject = $ subject; $ Mail-> AltBody = 'To view the message, please use an HTML compatible email viewer! '; // Optional, comment out and test $ Mail-> MsgHTML ($ body ); $ Address = 'admin @ admin.com '; // receiving email address $ Mail-> AddAddress ($ address ,''); // $ Mail-> AddAttachment ("images/phpmailer.gif"); // attachment // $ Mail-> AddAttachment ("images/phpmailer_mini.gif"); // attachment If (! $ Mail-> Send ()){ Echo 'mailer Error: '. $ mail-> ErrorInfo; } Else { // Echo "Message sent! Congratulations, the email is sent successfully! "; } } // Check server status Function checkServerSatatus ($ ip ){ $ Str = null; $ Fp = @ fsockopen ($ ip, 80, $ errno, $ errstr, 10 ); If (! $ Fp ){ Return false; } Else { Fclose ($ fp ); Return true; } } $ Server_ip_list = array ( '61. 135.169.121 ', '1970. 204.173.200 ', '194.127.83' ); ?>
Server Status Monitoring
Server online status monitoring
$ I ++; If (checkServerSatatus ($ server_ip_list [$ key]) { Echo"
?>
ID |
Location |
Address |
Status |
$ I = 0;Foreach ($ server_ip_list as $ key => $ val ){$ Api = file_get_contents ('HTTP: // ip.taobao.com/service/getIpInfo.php? Ip = '. $ server_ip_list [$ key]. '');$ Json = json_decode ($ api );$ Result = $ json-> data;
{$ I} |
{$ Result-> country} {$ result-> region} {$ result-> city} |
{$ Server_ip_list [$ key]} |
Online |
";} Else {Echo"
{$ I} |
{$ Result-> country} {$ result-> region} {$ result-> city} |
{$ Server_ip_list [$ key]} |
Not online |
";$ Subject = "your server {$ server_ip_list [$ key]} cannot be accessed! ";$ Body = "your server {$ server_ip_list [$ key]} cannot be accessed. This email is sent based on the monitoring frequency you set. When the server returns to normal, it will automatically stop sending emails! ";Sendmail ($ subject, $ body );}}
|
Note:
Include './smtp/class. smtp. php ';
Include './smtp/class. phpmailer. php ';
You can download the phpmailer package and copy the two files in the package to use it.
Ps: This is just a very simple one that cannot be well monitored to the server. Now there are many mature free products that can better meet our requirements, for example, there is a D monitoring in dnspod, and then we can operate it.