In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to configure and use the PHP error log, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
For PHP developers, once a project is put into use, the display_errors option in the configuration file php.ini should be turned off immediately to avoid hackers because of the path, database connection, data table and other information revealed by these errors.
But after any project is put into use, there will inevitably be errors, so how to record some error reports that are useful to developers? At this point, we can log the error report in a separate text file. The recording of the error log can help developers or managers to see if there is a problem with the system.
If you need to write the error report in the program to the error log, just turn on the configuration item log_errors in the configuration file of PHP.
Error reports are recorded in the log file of the Web server by default, for example, in the error log file error.log of the Apache server. Of course, you can also log the error log to the specified file or send it to the system's syslog, that is, the system log, so let's take a look at it separately.
Log error reporting using the specified file
If you want to log errors using a file you specify, make sure that the file is stored outside the document root to reduce the possibility of attack. And the file must have write permissions for the PHP script. First of all, we need to modify the configuration instructions in php.ini as follows:
Log_errors = On; determines where the log statement is recorded
Log_errors_max_len = 1024; set the maximum length of each log entry
Error_reporting = E_ALL; will report every error that occurs to PHP
Display_errors = Off; does not display all error reports that meet the rules defined in the previous directive
Error_log = / usr/local/error.log; specifies the location of the log file written to the resulting error report
After the configuration file for PHP is set as above, restart the Web server. In this way, when any script file in PHP is executed, any error reports generated will not be displayed in the browser, but will be recorded in the error log you specify.
In addition, not only can you log all errors that meet the rules defined by error_reporting, but you can also use the error_log () function in PHP to send error messages to the error log of the web server or to a file.
The prototype of the error_log () function is as follows:
Error_log (string $message [, int $message_type = 0 [, string $destination [, string $extra_headers]): bool
Among them, it should be noted that:
$message indicates the error message that needs to be logged; $destination indicates the destination to which the error message is sent. Its meaning is described above and is determined by the $message_type parameter; $extra_headers represents the extra header. Used when $message_type is set to 1. This information type uses the same built-in function of mail ().
$message_type indicates where the setting error should be sent. There are several possible types of information:
0: (default) send $message to PHP's system log, using the operating system's log mechanism or a file, depending on what error_log is set in the configuration file
1: send $message to the email address set by the parameter $destination. The fourth parameter, $extra_headers, is used only in this type; (2 has been deprecated)
The 3:$message is sent to a file located at $destination. The character $message is not treated as a new line by default
4: send $message directly to SAPI's log handler.
Next, let's take a look at logging in to the Mysql database as an example. When login fails, an error message is logged. Examples are as follows:
If you take the problem of logging in to Oracle database as an example, the use of this function is as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.