PHP online error log control (error_reporting and display_errors)

Source: Internet
Author: User
Tags php error php online

We know that the production environment of the product is definitely not incorrectly displayed, so:
Change display_errors = Off to display_errors = On in php. ini.
Or ini_set ('display _ errors ', 0 );

Secondly, we know that the php error level is controlled by error_reporting [error_reporting detailed tutorial], but many people disable the error message in the production environment.
Error_reporting (0 );

In fact, this practice is not scientific in my opinion. It is like this in the codeigniter framework.

The code is as follows: Copy code

If (defined ('enable '))
{
Switch (ENVIRONMENT)
 {
Case 'development ':
Error_reporting (E_ALL );
Break;
 
Case 'testing ':
Case 'production ':
Error_reporting (0 );
Break;
 
Default:
Exit ('The application environment is not set correctly .');
 }
}

Online error information must be recorded. error_reporting (0) will not record all error information. It should be: error_reporting = E_ALL &~ E_NOTICE: as long as display_errors = Off, the error message will not be displayed on the page, because display_errors has a higher priority.

Note:
If php. log_errors = On in ini. According to the official statement, the error_log file must be specified. If the specified file is not specified or the specified file does not have the write permission, the file will still be output to the normal output channel, in this case, the specified Off of display_errors is invalid, and the error message is printed. Set log_errors to Off.

In summary, the following error logs can be recorded for unrealistic error information in the production environment:

 

The code is as follows: Copy code
<? Php
/**
* Records production environment error logs
 *
* @ Link http://www.111cn.net
*/
Error_reporting (E_ALL );
Ini_set ('display _ errors ', 0 );
Ini_set ('log _ errors ', 1 );
Ini_set ('error _ log', 'E: \ '.date('y-m-d'{.'_phpddt.com.txt ');

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.