WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP Error and Logging functions


Introduction to PHP Error and Logging

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

Error function allows users to define error handling rules and modify how errors are logged.

Logging function allows users to log applications and send log messages to email, syslog, or other machines.


Perform configuration

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

Error and log configuration options:

parameters default Description Modifiable range
error_reporting NULL Sets the error level of PHP and returns the current level (number or constant). PHP_INI_ALL
display_errors "1" This option sets whether error messages are displayed on the screen as part of the output, or hidden from the user and not displayed.
Note: This feature should not be used in 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 highly recommended to set display_startup_errors to off for debugging purposes. PHP_INI_ALL
log_errors "0" Set whether to log the error information of the script to the server error log or error_log. Note that this is a specific configuration item related to the server. PHP_INI_ALL
log_errors_max_len "1024" Set the maximum number of bytes for log_errors. Information about the source of the error is added to error_log. The default value is 1024, if set to 0 it means unlimited length. This length setting has restrictions on recorded errors, displayed errors, and $ php_errormsg. PHP_INI_ALL
ignore_repeated_errors "0" Do not log duplicate information. Repeated errors must appear 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 duplicate messages, the source of the message is also ignored. When this setting is turned on, duplicate information will not record whether it was generated by a different file or a different line 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_ALL
PHP_INI_SYSTEM in PHP <= 4.2.3.
xmlrpc_errors "0" Turn off normal error reporting, and format the errors as XML-RPC error messages. PHP_INI_SYSTEM
xmlrpc_error_number "0" Used as the value of the XML-RPC faultCode element. PHP_INI_ALL
docref_root "" The new error message format includes a corresponding reference page, which specifically describes the error or describes the function that caused the error.
In order to provide the manual page, you can download the manual in the corresponding language on the official PHP site, and set the URL in the ini to the local corresponding address.
If your local manual copy is accessible using "/manual /", you can simply set docref_root = /manual /.
You also need to set docref_ext to match the suffix docref_ext = .html of your local file. Of course, you can also set an external reference address.
For example you can set docref_root = http: //manual /en /ordocref_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 output before the error message. PHP_INI_ALL
error_append_string NULL The output after the error message. PHP_INI_ALL
error_log NULL Set the file to which script errors will be logged. The file must be writable by the web server user. PHP_INI_ALL

Installation

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

PHP Error and Logging Functions

PHP: Indicates the earliest PHP version that supports this function.
function description PHP
debug_backtrace () Generate a backtrace. 4
debug_print_backtrace () Print a 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 () Resume the previous error handler. 4
restore_exception_handler () Resume the previous exception handler. 5
set_error_handler () Set a user-defined error handling function. 4
set_exception_handler () Set a user-defined exception handling function. 5
trigger_error () Create a user-defined error message. 4
user_error () Alias ​​for trigger_error (). 4

PHP Error and Logging constants

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

Value constant description PHP
1 E_ERROR Fatal error at runtime. Unrecoverable errors. Stop script execution.
2 E_WARNING A non-fatal error at runtime. Does not stop script execution.
4 E_PARSE A parse error during compilation. Parsing errors should only be generated by the parser.
8 E_NOTICE Runtime notifications. The script found may be an error, but it may also occur when the script runs normally.
16 E_CORE_ERROR User-generated notifications. This is like E_NOTICE generated by a programmer using the PHP function trigger_error (). 4
2048 E_STRICT Runtime notifications. PHP recommends that you change your code to improve code interoperability and compatibility. 5
4096 E_RECOVERABLE_ERROR Catchable fatal error. This is like an E_ERROR that can be captured by a user-defined handle (see set_error_handler ()). 5
6143 E_ALL All levels of errors and warnings except E_STRICT (Since PHP 6.0, E_STRICT will be part of E_ALL). 5
4
1024 E_USER_NOTICE User-generated notifications. This is like E_NOTICE generated by a programmer using the PHP function trigger_error (). 4
2048 E_STRICT Runtime notifications. PHP recommends that you change your code to improve code interoperability and compatibility. 5
4096 E_RECOVERABLE_ERROR Catchable fatal error. This is like an E_ERROR that can be captured by a user-defined handle (see set_error_handler ()). 5
6143 E_ALL All levels of errors and warnings except E_STRICT (Since PHP 6.0, E_STRICT will be part of E_ALL). 5