2. how does PHP record errors and send errors?
1. record the error to the specified file. the configuration process is as follows:
* 1). log_errors = on
* 2). error_log =/tmp/php_error.log
1. use the error_log () function to record error logs
Error_log ('error message to be logged! ');
Header ('content-type: text/html; charset = utf-8 '); // enable all error reports error_reporting (-1); // Set the time zone ini_set ('date. timezone ', 'prc'); // The error ini_set ('display _ errors', 0) is disabled on the page; // enable the logging function ini_set ('log _ errors ', 1); // set the location where error logs are stored, ini_set ('error _ log', '/tmp/custom_error.log '); // ignore duplicate error ini_set ('ignore _ repeated_errors ', 'on'); // ignore duplicate error source ini_set ('ignore _ repeated_source', 'on '); error_log ('I want to record you to my custom error log '. date ('Y-m-d H: I: S', time ())); trigger_error ('trigger _ error ----- I want to record you to my system error log '. date ('Y-m-d H: I: S', time (), E_USER_NOTICE); settype ($ var, 'king ');
2. record errors to system logs
* 1. ini_set ('error _ log', 'syslog '); commonly used
Method 1 // enable all error reports error_reporting (-1); // disable the page to display the error ini_set ('display _ errors ', 0 ); // enable the logging function ini_set ('log _ errors ', 1); // set the location where error logs are stored ------ (System log) ini_set ('error _ log ', 'syslog '); // ignore duplicate error ini_set ('ignore _ repeated_errors', 'on'); // ignore duplicate error source ini_set ('ignore _ repeated_source ', 'on'); // error_log ('error _ log ----- I want to record you to my system error log '. date ('Y-m-d H: I: S', time ())); trigger_error ('trigger _ error ----- I want to record you to my system error log '. date ('Y-m-d H: I: S', time (), E_USER_NOTICE); // settype ($ var, 'king '); method 2 ====================/// openlog ('php5. 6.0 ', LOG_PID, LOG_SYSLOG); syslog (LOG_ERR, 'This is a test syslog '. date ('Y-m-d H: I: S', time (); closelog ();
2. send the error log by email
* 1. error_log ('MSG ', 1, mail_addr); the second parameter is set to 1
** Bool error_log (string $ message [, int $ message_type = 0 [, string $ destination [, string $ extra_headers])
Error message to be recorded. Where should the message_type setting error be sent. The possible information types are as follows: error_log () the log type 0 message is sent to the PHP System Log. the operating system's log mechanism or a file depends on what the error_log command sets. This is a default option. 1. message is sent to the email address set by destination. The fourth parameter extra_headers is used only in this type. 2 is no longer an option. 3. the message is sent to the file at the destination location. The message character is not treated as a new row by default. 4. message is directly sent to the SAPI log handler. Destination target. Its meaning is described above and determined by the message_type parameter. Extra_headers. It is used when message_type is set to 1. This information type uses the same built-in function of mail.
// Enable all error reports: error_reporting (-1); // disable the ini_set ('display _ errors ', 0 ); // enable the logging function ini_set ('log _ errors ', 1); // ignore duplicate errors ini_set ('ignore _ repeated_errors', 'on '); // ignore repeated error sources ini_set ('ignore _ repeated_source ', 'on'); // set the second parameter to 1, use the error log message error_log ('error _ log ----- I want to record you to my system error log '. date ('Y-m-d H: I: S', time (), 1, '2017 @ qq.com ');
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.