PHP Error



Introduction to PHP Error and Logging

The Error and Logging functions allow you to handle and log errors.

The Error function allows users 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.


Execution configuration

error function is affected by the php.ini configuration file.

Error and log configuration options:

##xmlrpc_errors"0"Close normally error report and format the error to the XML-RPC error message format. PHP_INI_SYSTEMxmlrpc_error_number"0"The value used as the XML-RPC faultCode element. PHP_INI_ALLdocref_root""The new error message format contains the corresponding reference page, which is a reference page for errors. Provide a specific description, or describe the function that caused the error.
ParametersDefault valueDescriptionModifiable range
error_reporting NULLSet PHP's error level and return 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: Do not use this feature 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 the error information of the script running to the server error log or error_log among. Note that this is a server-specific configuration item. PHP_INI_ALL
log_errors_max_len"1024"Set the maximum number of bytes of log_errors. Related error sources will be added to error_log Information. The default value is 1024. If set to 0, there is no limit to the length. This length setting limits logged errors, displayed errors, and $php_errormsg. PHP_INI_ALL
ignore_repeated_errors"0"Do not log duplicate information. 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 ignoring repeated messages, 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, the memory leak information will not be displayed ( in stdout or log). PHP_INI_ALL
track_errors"0"If turned on, the last error will always exist in the variable $php_errormsg . PHP_INI_ALL
html_errors"1"Close the HTML tag in the error message. PHP_INI_ALL
PHP_INI_SYSTEM in PHP <= 4.2.3.
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_stringNULLThe content output before the error message. PHP_INI_ALL
error_append_stringNULLThe content output after the error message. PHP_INI_ALL
error_logNULLSets the file to which script errors will be logged. The file must be writable by the web server user. PHP_INI_ALL

Installation

The Error and Logging functions are part of the PHP core. No installation is required to use these functions.


PHP Error and Logging Functions

PHP: Indicates the earliest PHP version that supports this function.

FunctionDescriptionPHP
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 target. 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 Error and Logging Constants

PHP: Indicates the earliest PHP version that supports this constant.

##1 E_ERROR Fatal error at runtime. Unfixable errors. Stop executing the script. 2E_WARNINGNon-fatal runtime error. Script execution is not stopped. 4E_PARSEParse error during compilation. Parsing errors should only be generated by the parser. 8E_NOTICERuntime notification. Script discovery can be a bug, but can also occur when running a script normally. 16E_CORE_ERRORFatal error when starting PHP. This is just like PHP core's E_ERROR. 432E_CORE_WARNINGNon-fatal error when starting PHP. This is just like PHP core's E_WARNING. 464E_COMPILE_ERROR Fatal error during compilation. This is just like the E_ERROR generated by the Zend scripting engine. 4128E_COMPILE_WARNINGNon-fatal error during compilation. This is like an E_WARNING generated by the Zend scripting engine. 4256E_USER_ERRORUser-generated fatal error. This is like the E_ERROR generated by the programmer using the PHP function trigger_error(). 4512E_USER_WARNING User-generated non-fatal error. This is like an E_WARNING generated by the programmer using the PHP function trigger_error(). 41024E_USER_NOTICE User-generated notification. This is like the E_NOTICE generated by the programmer using the PHP function trigger_error(). 42048E_STRICTRuntime notification. PHP recommends that you make changes to your code to improve code interoperability and compatibility. 54096E_RECOVERABLE_ERRORCatchable fatal error. This is like an E_ERROR that can be caught by a user-defined handle (see set_error_handler()). 56143E_ALLAll error and warning levels except E_STRICT (since PHP 6.0, E_STRICT will be part of E_ALL). 5
ValueConstantDescriptionPHP