The Error and Logging functions allow you to handle and log errors.
The Error function allows the user to define error handling rules and modify the way errors are logged.
The Logging function allows users to log applications and send log messages to email, system logs, or other machines.
The error function is affected by the php.ini configuration file.
Error and log configuration options:
parameter | default value | describe | Modifiable range |
---|---|---|---|
error_reporting | NULL | Sets PHP's error level and returns the current level (number or constant). | PHP_INI_ALL |
display_errors | "1" | This option sets whether error messages are displayed to the screen as part of the output, or hidden from the user. Note: This feature should not be used in the production environment (used during development and testing) | PHP_INI_ALL |
display_startup_errors | "0" | Even if display_errors is set to on, error messages during PHP startup will not be displayed. It is strongly recommended to set display_startup_errors to off except for debugging purposes. | PHP_INI_ALL |
log_errors | "0" | Set whether to record script running error information to the server error log or error_log. Note that this is a server-specific configuration item. | PHP_INI_ALL |
log_errors_max_len | "1024" | Set the maximum number of bytes in log_errors. Information about the source of the error will be added to error_log. The default value is 1024. If set to 0, there is no limit to the length. This length setting has a limiting effect on logged errors, displayed errors, and $php_errormsg. | PHP_INI_ALL |
ignore_repeated_errors | "0" | Duplicate information is not logged. Repeated errors must occur on the same line of code in the same file, unless ignore_repeated_source is set to true. | PHP_INI_ALL |
ignore_repeated_source | "0" | When duplicate messages are ignored, the source of the message is also ignored. When this setting is on, duplicate messages will not record whether they were generated by different files or different lines of source code. | PHP_INI_ALL |
report_memleaks | "1" | If this parameter is set to Off, memory leak information will not be displayed (in stdout or logs). | PHP_INI_ALL |
track_errors | "0" | If enabled, the last error will always exist in the variable $php_errormsg. | PHP_INI_ALL |
html_errors | "1" | Close HTML tags in error messages. | PHP_INI_ALLPHP_INI_SYSTEM in PHP <= 4.2.3. |
xmlrpc_errors | "0" | Turns off normal error reporting and formats errors as XML-RPC error messages. | PHP_INI_SYSTEM |
xmlrpc_error_number | "0" | Used as the value for the XML-RPC faultCode element. | PHP_INI_ALL |
docref_root | "" | The new error message format includes a corresponding reference page that specifically describes the error or describes the function that caused the error. In order to provide manual pages, you can download the corresponding language manual from the PHP official site and set the URL in the ini to the local corresponding address. If your local copy of the manual is accessible using "/manual/", you can simply set docref_root=/manual/. In addition, you also need to set docref_ext to match the suffix of your local file docref_ext=.html. Of course, you can also set an external reference address. For example you can set docref_root=http://manual/en/ or docref_root="http://landonize.it/?how=url&theme=classic&filter=Landon &url=http%3A%2F%2Fwww.php.net%2F" | PHP_INI_ALL |
docref_ext | "" | See docref_root. | PHP_INI_ALL |
error_prepend_string | NULL | The content output before the error message. | PHP_INI_ALL |
error_append_string | NULL | The content output after the error message. | PHP_INI_ALL |
error_log | NULL | Sets the file to which script errors will be logged. The file must be writable by the web server user. | PHP_INI_ALL |
The Error and Logging functions are part of the core of PHP. No installation is required to use these functions.
PHP : Indicates the earliest PHP version that supports this function.
function | describe | PHP |
---|---|---|
debug_backtrace() | Generate backtrace. | 4 |
debug_print_backtrace() | Print backtrace. | 5 |
error_get_last() | Get the last error that occurred. | 5 |
error_log() | Send an error to the server error log, file, or remote destination. | 4 |
error_reporting() | Specifies which error to report. | 4 |
restore_error_handler() | Restore the previous error handler. | 4 |
restore_exception_handler() | Restore the previous exception handler. | 5 |
set_error_handler() | Set user-defined error handling function. | 4 |
set_exception_handler() | Set user-defined exception handling function. | 5 |
trigger_error() | Create user-defined error messages. | 4 |
user_error() | Alias for trigger_error(). | 4 |
PHP : Indicates the earliest PHP version that supports this constant.
value | constant | describe | PHP |
---|---|---|---|
1 | E_ERROR | Runtime fatal error. Unfixable errors. Stop executing the script. | |
2 | E_WARNING | Non-fatal runtime error. Script execution is not stopped. | |
4 | E_PARSE | Compile time parsing error. Parsing errors should only be generated by the parser. | |
8 | E_NOTICE | Runtime notifications. Script discovery can be a bug, but can also occur when running a script normally. | |
16 | E_CORE_ERROR | Fatal error on PHP startup. This is just like PHP core's E_ERROR. | 4 |
32 | E_CORE_WARNING | Non-fatal error when starting PHP. This is just like PHP core's E_WARNING. | 4 |
64 | E_COMPILE_ERROR | Fatal compile-time error. This is just like the E_ERROR generated by the Zend scripting engine. | 4 |
128 | E_COMPILE_WARNING | Non-fatal compile-time error. This is like an E_WARNING generated by the Zend scripting engine. | 4 |
256 | E_USER_ERROR | User-generated fatal error. This is like the E_ERROR generated by the programmer using the PHP function trigger_error(). | 4 |
512 | E_USER_WARNING | User-generated non-fatal error. This is like an E_WARNING generated by the programmer using the PHP function trigger_error(). | 4 |
1024 | E_USER_NOTICE | User-generated notifications. This is like the E_NOTICE generated by the programmer using the PHP function trigger_error(). | 4 |
2048 | E_STRICT | Runtime notifications. PHP recommends that you make changes to your code to improve code interoperability and compatibility. | 5 |
4096 | E_RECOVERABLE_ERROR | Trapable fatal errors. This is like an E_ERROR that can be caught by a user-defined handle (see set_error_handler()). | 5 |
6143 | E_ALL | All error and warning levels except E_STRICT (since PHP 6.0, E_STRICT will be part of E_ALL). | 5 |