Use PHP to capture the bug in PHP's source code and send an email notification, Javaemail sending _php tutorial

Source: Internet
Author: User

Use PHP to capture the bug in PHP's source code and send an email notification, Javaemail sent


Developers of PHP know that the most worrying thing is that there are some abnormalities or mistakes in the program, these situations, if the user's screen is dropped to scare the user, or even lose the job, if you do not output to the screen will have to be recorded in the journal, but it does not seem that everyone has to look at the wrong Journal of the Habit, To understand the problem of this awkwardness embarrassed, so I wrote this code, which is meant to capture the bug content and send it to our email when the PHP program we wrote was wrong.
First look at the effect:

Define(' Sys_debug ',false);IF(sys_debug) {Ini_set(' Display_errors ', ' on ');error_reporting(E_all);//use the setting error_reporting after the line (E_error | e_warning | E_parse);}Else{Ini_set(' display_errors ', ' off ');error_reporting(0);}//Bug Captureregister_shutdown_function(' Fun::error ');Classfun{/** General Fault handling parameters: the content to be output, whether the end of the program says: There is a value when the function can be used to output the wrong content of the definition can also cooperate with register_shutdown_function to automatically crawl the wrong content, And will crawl the wrong content to send to the register_shutdown_function in the email system is the program after the completion or the middle of the wrong time to adjust the function if it is a self-fetching bug is adjusted, it will get the last mistake of the content, if there is no mistake inside to jump back: The content will be directly output to the screen or email usage: fun::error (' bug content '); Fun::error (' Wrong content ', False);/**/ Public Static FunctionError ($M='',$E=True){$ERRTPL='
 
  
 
 
 
;$M=Trim($M);IF($M!='') {//Manual Adjustments$M='Note:'.$M;Echo STRTR($ERRTPL,Array(' {$M} ' =$M));UnSet($ERRTPL);IF($E===True) { die();}Return ;}Else{//The program performs the auto crawl bug when$M=error_get_last ();//make the final mistake.IF(!Is_array($M) OrCount($M) {<4) {Unset($M);Return ;}IF(!file_exists($M[' File ']) {Unset($M);Return ;}//get 5 lines out of the wrong key code, if you do not get the content, stating that the wrong file does not exist$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)? ''. ($M[' line ']-3) + ($i+ 1)). '' : (($M[' line ']-3) + ($i+1));$E[' M '].= ': '.Htmlspecialchars($E[$i],ent_quotes, ' UTF-8 '). '
';}$E=&$E[' M '];$M='self-capturing to have the wrong product!

description of the bug:
'. $M [' file ']. 'The first'. $M [' line ']. 'The line is that the type'. $M [' type ']. 'The BUG:
'.$M[' message ']. '

Key codes:
'.$E.'
'. Self::now (' y-m-d h:i:s ', Time()).'
';$M=STRTR($ERRTPL,Array(' {$M} ' =$M));UnSet($ERRTPL);$G=SEFT::GETG (' SYS ', ' config ');IF(!self::mail2 ($G[' Spe '], ' Warning: '.$G[' Tit ']. ' PHP program Bug! ',$M) and sys_debug===True){Throw New Exception(' Warning: '.$G[' Tit ']. ' PHP program Bug!

'.$M);}IF(Sys_debug) {Echo $M;}UnSet($E,$M,$G); die();}}/** Send e-mail parameters: recipient, email title (No line break), email content (line and line must be separated by \ n, each line cannot exceed 70 characters) stating: Adjusting with PHP internal function mail send back: Return to value usage: $IsSend =fun::mail2 ( $email, $tit, $msg);/**/ Public Static FunctionMAIL2 ($to,$tit,$msg) {IF(Filter_var ($to, filter_validate_email) = = "){Throw New Exception(' Email address is wrong! '));}$tit='=? UTF-8? B? '.Base64_encode($tit).'? =';$msg=Str_replace("\ n.", "\ n..",$msg);//If Windows finds a period at the beginning of a line, it will be deleted, to avoid the issue of replacing a single period with two periodsReturn Mail($to,$tit,$msg, ' from: '. SEFT::GETG (' Config/sys/mal '). " \ n "." Content-type:text/html;charset=utf-8 ');}}

http://www.bkjia.com/PHPjc/1130143.html www.bkjia.com true http://www.bkjia.com/PHPjc/1130143.html techarticle using PHP to capture the bug in PHP's original code and send an email notification, Javaemail send PHP's friends know that the most worrying is that the program is some of the abnormal or wrong, these situations ...

  • 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.