Home php教程 PHP源码 监控日志,发现500 503 等错误发送邮件提示

监控日志,发现500 503 等错误发送邮件提示

May 25, 2016 pm 05:03 PM
500 Discover

php代码

<?php
include("PHPMailer/class.phpmailer.php");
//error_reporting(0);
$mail             = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.126.com"; // sets the SMTP server
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "xxx@126.com"; // SMTP account username 邮箱用户名
$mail->Password   = "xxxxxxxxx";        // SMTP account password 密码
$mail->SetFrom(&#39;xxxxxxx@126.com&#39;, &#39;报错&#39;);//


$now = "u_ex".date("ymdH").".log";

try{
    $log = file("F:/iis-log/W3SVC2/".$now);//日志路径自己改
}catch(Exception $e){
    echo "no file ";
    exit;
 }

$error = array();
$start = date("i",time()-120);
$end = date("i");
if($start > $end){
    exit;
}
$aa = range($start,$end);
$code = mkstr($aa);
echo $code;
$pattern = "/($code).*(\s500\s|\s503\s)/";//这里自己修改
$i = 0;
foreach($log as $k => $v){
    if(preg_match($pattern,$v)){
        $error[] =  $v;
		echo $v;
		$i += 1;
    }
}
if(!empty($error)){
	$content = implode("<br/>",$error);
	$mail->Subject="$i errors ";
	$mail->AddAddress("xxxxxxxxxx@163.com");
	$mail->AddAddress("xxxxxxxx@126.com");
	$mail->MsgHTML($content);
	$mail->send();
}
echo "\nover";
function mkstr($arr){
    $code = &#39;&#39;;
    foreach($arr as $k => $e){
        $code .="\:$e\:|";
    }
    $code = rtrim($code,"|");
    return $code;
}
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Application of Redis in service registration and discovery Application of Redis in service registration and discovery Jun 20, 2023 am 08:39 AM

Redis is a high-performance key-value database. Through its fast data storage and access capabilities, it is widely used in the process of service registration and discovery. Service registration and discovery is a very important process in distributed systems. When we run multiple services on a machine, we need a way for clients to discover these services and how to interact with them. In a complete distributed system, there may be dozens of services running, and manual configuration has become unfeasible. At this time, we need to use service registration and discovery.

Autonomous robot discovers toughest structure known Autonomous robot discovers toughest structure known Sep 08, 2023 pm 03:57 PM

A robotics laboratory BEAR. Image source: Boston University According to a report on the British "New Scientist" magazine website on August 29, a robotic laboratory in the United States has discovered the toughest structure known so far. The laboratory can conduct 50 experiments a day without human supervision. , fabricate and test the mechanical structure. The latest research is expected to accelerate the discovery of new materials, and related papers have been submitted to a preprint website. In this latest study, Boston University researchers said they used an autonomous robotic laboratory called the Bayesian Experimental Autonomous Researcher (BEAR) to discover the most energy-absorbing material structure known to date. BEAR consists of five 3D printers, a set of scales, a testing machine, a robotic arm and computer vision for moving samples

What does 500internal server error mean? What does 500internal server error mean? Feb 21, 2023 pm 03:39 PM

500internal server error means HTTP 500 internal server error, which means that the server encountered an unexpected situation that caused it to be unable to fulfill the request, but it cannot explain the specific error or the root cause of the error; when an error occurs, the website visited will display an error. .

Service registration and discovery in Go language Service registration and discovery in Go language Jun 01, 2023 am 09:12 AM

With the development of microservice architecture, service registration and discovery are becoming more and more important. For the Go language, due to its high efficiency and excellent concurrency performance, it is becoming more and more popular as a development language for microservices. This article will introduce how to register and discover services in Go language. What is service registration and discovery? Service registration and discovery means that the service provider registers its service to the service registration center, and the service consumer obtains the available service list from the registration center and calls the corresponding service. The service registry can be a separate process or a separate

Ethereum (ETH) Price Recovers Above $2,320, But Struggles to Gain Pace Ethereum (ETH) Price Recovers Above $2,320, But Struggles to Gain Pace Sep 10, 2024 pm 03:20 PM

Ethereum price started a recovery wave above the $2,250 level. ETH was able to clear the $2,280 resistance zone to move into a positive zone, but momentum was weak compared to Bitcoin.

Brits urged to check at home for rare 50p coin that could be worth £2,500 Brits urged to check at home for rare 50p coin that could be worth £2,500 Oct 28, 2024 pm 04:20 PM

According to one expert, the 2011 piece was minted to celebrate the London Olympics in 2012

Bitcoin (BTC) Price Analysis: BTC Initiates Significant Upward Movement, Targets $60,000 Mark Bitcoin (BTC) Price Analysis: BTC Initiates Significant Upward Movement, Targets $60,000 Mark Sep 12, 2024 pm 06:35 PM

Bitcoin has initiated a significant upward movement, surpassing the $57,500 resistance level and now showing promising signs of potentially reaching the $60,000 mark.

The Solana Price Can Reach $4,500 The Solana Price Can Reach $4,500 Oct 22, 2024 am 06:42 AM

SOL has formed a cup-and-handle pattern on its weekly chart, which shows that the Solana price can surge by 2,600% and rise to $4,500.

See all articles