Use PHP to instantly capture zookeeper in the original PHP repository and send an email notification.

Source: Internet
Author: User
When using PHP, you can instantly capture zookeeper in the original PHP repository and send an email to notify anyone who is developing PHP, in fact, the most worrying thing is that there are some regular or temporary errors in the program. if these errors occur, the screen of the website will be sent to the website administrator, even if I quit my job, I have to try to remember it to my daily routine if I don't leave it on the screen, however, it does not seem that everyone has looked at the issue of daily failover. in order to understand this issue, I chose this generation, the intention is to capture the internal content when our php program is released and then send it to our email.
First look at the effect:

Define ('sys _ debug', false); IF (SYS_DEBUG) {ini_set ('display _ errors ', 'on'); Error_reporting (E_ALL ); // Set Error_reporting (E_ERROR | E_WARNING | E_PARSE) using the setting after the upload;} Else {ini_set ('display _ errors ', 'off'); Error_reporting (0 );} // zookeeper captures Register_shutdown_function ('fun: error'); Class Fun {/** general output handler parameter: content to be exported, whether to stop the program: when there is a threshold value, the function can be used to specify the custom internal volume content. In addition, it can be used with Register_shutdown_function to automatically capture internal volume content, and send the captured response content to the Email body. use, in this case, the last outbound content will be obtained. If no internal content exists, the system will jump out and return: The content will be directly exported to the screen or Email usage: fun: Error ('internal internal content'); Fun: Error ('internal internal content', False ); /**/Public Static Function Error ($ M = '', $ E = True) {$ ErrTpl ='
 
 
 
{$ M}
'; $ M = Trim ($ M); IF ($ M! = '') {// Manually renew $ M ='Note:'. $ M; Echo Strtr ($ ErrTpl, Array ('{$ M}' => $ M); unSet ($ ErrTpl); IF ($ E = True) {Die ();} Return;} Else {// when the program completes automatic capturing of the primary node, $ M = error_get_last () is used (); // obtain the final generated response IF (! Is_array ($ M) Or Count ($ M) <4) {Unset ($ M); Return;} IF (! File_Exists ($ M ['file']) {Unset ($ M); Return;} // Get 5 rows out of the primary key, if not, it is stated that the zookeeper case 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 ='This product is automatically captured!

Zookeeper description:
'. $ M ['file'].'The'. $ M ['line'].'Now the type is'. $ M ['type'].'Zookeeper:
'. $ M ['message'].'

Relational proxy service:
'. $ 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 ['SP'], 'warning:'. $ G ['tit']. 'The PHP program has been released! ', $ M) And SYS_DEBUG = True) {throw new Exception ('Warning:'. $ G ['tit']. 'The PHP program has been released!

'. $ M) ;}if (SYS_DEBUG) {Echo $ M;} unSet ($ E, $ M, $ G); Die ();}} /** email sending parameter: recipient, email subject (cannot have a line character), and email content (\ n must be used to separate rows and rows, each line must not exceed 70 characters.) description: you can use a PHP internal Mail to send a Mail to a mailbox and return the following message: return the publish value. usage: $ IsSend = Fun :: mail2 ($ email, $ tit, $ msg);/**/Public Static Function Mail2 ($ to, $ tit, $ msg) {IF (Filter_var ($ to, FILTER_VALIDATE_EMAIL) = '') {throw new Exception ('email address success! ') ;}$ Tit =' =? UTF-8? B? '. Base64_Encode ($ tit ).'? = '; $ Msg = str_replace ("\ n. "," \ n .. ", $ msg); // if a period is found at the beginning of a line in Windows, it will be deleted. to avoid this problem, replace a period with two periods: Return Mail ($, $ tit, $ msg, 'From :'. seft: getG ('config/SYS/Mal '). "\ n ". 'content-Type: text/html; charset = utf-8 ');}}

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.