PHP implementation of Server Status monitoring method, PHP implementation of server monitoring _php tutorial

Source: Internet
Author: User
Tags php server set time

PHP implementation of Server Status monitoring method, PHP implementation of server monitoring


This paper describes the method of implementing server state Monitoring by PHP. Share to everyone for your reference. The specific analysis is as follows:

PHP Server Status Monitoring for many friends do not do, only to see the site hanging to know, this midnight site is not aware of the situation, for the site is also very bad, for this two days to write a Web server state monitoring, see a friend said need, then I put it out. Very simple stuff.

How to use:

Open the status.php file inside the compressed package. Edit the content here for your own mailbox information. The code is as follows:
Copy CodeThe code is as follows: $mail->host = ' smtp.exmail.qq.com '; SMTP Server
$mail->port = 25; Port number of the SMTP server
$mail->username = ' admin@xxx.com '; SMTP Server user name
$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 '; Receive mailbox
Change the content here for the IP you want to monitor:
$server _ip_list = Array (
' 61.135.169.121 ',
' 221.204.173.200 ',
' 173.194.127.83 '
);
Then visit your http://yourdomain.com/status.php file to see the current server status and automatically send mail to the mailbox you set up. If you need automatic monitoring, add cron tasks or use any surveillance treasure or something!
The complete code is as follows:
Copy CodeThe code is as follows: <?php
/*
* 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 time zone East eight zone
$mail = new Phpmailer (); New a Phpmailer object.
$body = Eregi_replace ("[]", "', $body); Filtering the content of the message as necessary
$mail->charset = "UTF-8";//Set the message encoding, default iso-8859-1, if the Chinese language must be set, otherwise garbled
$mail->issmtp (); Setting up using the SMTP service
$mail->smtpauth = true; Enable the SMTP authentication feature
$mail->host = ' smtp.exmail.qq.com '; SMTP Server
$mail->port = 25; Port number of the SMTP server
$mail->username = ' admin@xxx.com '; SMTP Server user name
$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 '; Receive mailbox
$mail->addaddress ($address, ');
$mail->addattachment ("Images/phpmailer.gif"); Attachment Accessories
$mail->addattachment ("Images/phpmailer_mini.gif"); Attachment
if (! $mail->send ()) {
Echo ' Mailer Error: '. $mail->errorinfo;
} else {
echo "Message sent! Congratulations, Mail sent successfully! ";
}
}
Check Server Status
function Checkserversatatus ($IP) {
$STR = null;
$fp = @fsockopen ($ip, $errno, $ERRSTR, 10);
if (! $fp) {
return false;
} else {
Fclose ($FP);
return true;
}
}
$server _ip_list = Array (
' 61.135.169.121 ',
' 221.204.173.200 ',
' 173.194.127.83 '
);
?>




<title>Server Status Monitoring</title>




Server Online Status Monitoring

























<?php $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 + +; if (Checkserversatatus ($server _ip_list[$key])) {echo " "; } else {echo ' "; $subject = "Your server {$server _ip_list[$key]} cannot be accessed! "; $body = "Your server {$server _ip_list[$key]} cannot be accessed, this message is sent according to the monitoring frequency you set, when the server resumes normal mail automatically stop sending! "; SendMail ($subject, $body); }}?>
Id Location Address Status
{$i} {$result->country} {$result->region} {$result->city} {$server _ip_list[$key]} Online
{$i} {$result->country} {$result->region} {$result->city} {$server _ip_list[$key]} Not online





Attention:
Include './smtp/class.smtp.php ';
Include './smtp/class.phpmailer.php ';
The file can download the Phpmailer package and then we'll copy the two files out of the package and then we can use them.

PS: This is just a very simple not very good monitoring to the server, now have a lot of mature free products can better meet our requirements, such as dnspod inside there is a D monitoring, and then we can operate.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/924537.html www.bkjia.com true http://www.bkjia.com/PHPjc/924537.html techarticle PHP Implementation of server Status monitoring methods, PHP implementation of server monitoring This article describes the PHP implementation of server status monitoring methods. Share to everyone for your reference. The specific analysis is as follows: ...

  • Related Article

    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.