Home > Backend Development > PHP Tutorial > 用PHP即?捕捉PHP原始?中的??并?送email通知

用PHP即?捕捉PHP原始?中的??并?送email通知

WBOY
Release: 2016-06-23 14:37:44
Original
1101 people have browsed it

??PHP的朋友都知道,其?最?心的就是程序中出?一些?常或??,?些??如果?出到用?的?幕?把用????,甚至?此?了工作,如果不?出到?幕就得想?法??到日?中,但是似乎不是每?人都有查看??日?的??,?了解????尬的??,所以我?了?段代?,其用意就是?我??的php程式出?的?候把???容捕捉出?然後?到我?的email?.
先看效果:

 

Define('SYS_DEBUG',false);IF(SYS_DEBUG) {ini_set('display_errors','on');Error_reporting(E_ALL);//上?后使用??定Error_reporting(E_ERROR | E_WARNING | E_PARSE);}Else{ini_set('display_errors','off');Error_reporting(0);}//??捕捉Register_shutdown_function('Fun::Error');Class Fun{/**通用出??理参数:要?出的?容,是否?止?行程序?明:有?值??函式可以用??出自定?的???容另外?可以配合Register_shutdown_function??自?抓取???容,??抓取的???容?送到Email?Register_shutdown_function的?制是程序?行完?或中途出???用函?如果是自?抓取???被?用,??取得最後一次出?的?容,如果???有???容?跳出返回:?容?被直接?出至?幕或Email?用法:Fun::Error('???容');Fun::Error('???容',False);/**/Public Static Function Error($M='',$E=True){$ErrTpl='<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><table cellspacing="0" cellpadding="0" border="0"><tr><td style="padding:5px;background-color:#F57900;font-size:13px;border:1px solid #444;color:#222;">{$M}</td></tr></table>';$M=Trim($M);IF($M!='') {//手工?用$M=' <b>注意:</b> '.$M;Echo Strtr($ErrTpl,Array('{$M}'=>$M));unSet($ErrTpl);IF($E===True) {Die();}Return ;}Else{//程式?行完?自?抓取????用$M=error_get_last();//取得最後?生的??IF(!Is_array($M) Or Count($M)<4) {Unset($M);Return ;}IF(!File_Exists($M['file'])) {Unset($M);Return ;}//取得5行出???代?,如果取不到?容,?明出??案不存在$E=Array_slice(File($M['file']),($M['line']-4),5);IF(!Is_array($E)) {Unset($M,$E);Return ;}$E['M']='';For($i=0;$i<5;$i++) {$E[$i]=isSet($E[$i]) ? $E[$i] : '';$E['M'].='  ';$E['M'].=($i==3) ? '<b>'.(($M['line']-3)+($i+1)).'</b>' : (($M['line']-3)+($i+1));$E['M'].=': '.Htmlspecialchars($E[$i],ENT_QUOTES,'UTF-8').'<br>';}$E=&$E['M'];$M='<b>自?捕捉到有???生!</b><br><br><b>??描述:</b><br>  <b>'.$M['file'].'</b>的第<b>'.$M['line'].'</b>行出?了?型?<b>'.$M['type'].'</b>的??:<br>  '.$M['message'].'<br><br><b>??代?:</b><br>'.$E.'<br>'.self::now('Y-m-d H:i:s',time()).'<br>';$M=Strtr($ErrTpl,Array('{$M}'=>$M));unSet($ErrTpl);$G=seft::getG('SYS','config');IF(!self::Mail2($G['Spe'],'警告: '.$G['Tit'].' 出? PHP 程式??!',$M) And SYS_DEBUG===True){throw new Exception('警告: '.$G['Tit'].' 出? PHP 程式??!<br><br>'.$M);}IF(SYS_DEBUG) {Echo $M;}unSet($E,$M,$G);Die();}}/**发送??参数:收件人,?件??(不可有?行符),?件?容(行?行之?必?用\n分隔,每行不可超?70?字符)?明:?用PHP?置函式Mail?送??返回:返回布?值用法:$IsSend=Fun::Mail2($email,$tit,$msg);/**/Public Static Function Mail2($to,$tit,$msg) {IF(Filter_var($to,FILTER_VALIDATE_EMAIL)==''){throw new Exception('??地址??!');}$tit='=?UTF-8?B?'.Base64_Encode($tit).'?=';$msg = str_replace("\n.","\n..",$msg);     //Windows如果在一行开头发现一个句号则会被删掉,要避免此问题将单个句号替换成两个句号Return Mail($to,$tit,$msg,'From:'.seft::getG('config/SYS/Mal')."\n".'Content-Type:text/html;charset=utf-8');}}
Copy after login

 

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template