Monday, 26 August 2013

PHP Error and Logging Functions

These are functions dealing with error handling and logging. They allow you to define your own error handling rules, as well as modify the way the errors can be logged. This allows you to change and enhance error reporting to suit your needs.
Using these logging functions, you can send messages directly to other machines, to an email, to system logs, etc., so you can selectively log and monitor the most important parts of your applications and websites.

Installation:

The error and logging functions are part of the PHP core. There is no installation needed to use these functions.

Runtime Configuration:

The behaviour of these functions is affected by settings in php.ini. These settings are defined below.
NameDefaultChangeableChangelog
error_reportingNULLPHP_INI_ALL 
display_errors"1"PHP_INI_ALL 
display_startup_errors"0"PHP_INI_ALLAvailable since PHP 4.0.3.
log_errors"0"PHP_INI_ALL 
log_errors_max_len"1024"PHP_INI_ALLAvailable since PHP 4.3.0.
ignore_repeated_errors"0"PHP_INI_ALLAvailable since PHP 4.3.0.
ignore_repeated_source"0"PHP_INI_ALLAvailable since PHP 4.3.0.
report_memleaks"1"PHP_INI_ALLAvailable since PHP 4.3.0.
track_errors"0"PHP_INI_ALL 
html_errors"1"PHP_INI_ALLPHP_INI_SYSTEM in PHP <= 4.2.3. Available since PHP 4.0.2.
docref_root""PHP_INI_ALLAvailable since PHP 4.3.0.
docref_ext""PHP_INI_ALLAvailable since PHP 4.3.2.
error_prepend_stringNULLPHP_INI_ALL 
error_append_stringNULLPHP_INI_ALL 
error_logNULLPHP_INI_ALL 
warn_plus_overloadingNULL This option is no longer available as of PHP 4.0.0

PHP Error and Logging Constants:

PHP: indicates the earliest version of PHP that supports the constant.
You can use any of the constant while configuring your php.ini file.
ValueConstantDescriptionPHP
1E_ERRORFatal run-time errors. Errors that cannot be recovered from. Execution of the script is halted 
2E_WARNINGNon-fatal run-time errors. Execution of the script is not halted 
4E_PARSECompile-time parse errors. Parse errors should only be generated by the parser 
8E_NOTICERun-time notices. The script found something that might be an error, but could also happen when running a script normally 
16E_CORE_ERRORFatal errors at PHP startup. This is like an E_ERROR in the PHP core4
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is like an E_WARNING in the PHP core4
64E_COMPILE_ERRORFatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine4
128E_COMPILE_WARNINGNon-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine4
256E_USER_ERRORFatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()4
512E_USER_WARNINGNon-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()4
1024E_USER_NOTICEUser-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()4
2048E_STRICTRun-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code5
4096E_RECOVERABLE_ERRORCatchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())5
8191E_ALLAll errors and warnings, except of level E_STRICT5

List of Functions

PHP: indicates the earliest version of PHP that supports the function.
FunctionDescriptionPHP
debug_backtrace()Generates a backtrace4
debug_print_backtrace()Prints a backtrace5
error_get_last()Gets the last error occurred5
error_log()Sends an error to the server error-log, to a file or to a remote destination4
error_reporting()Specifies which errors are reported4
restore_error_handler()Restores the previous error handler4
restore_exception_handler()Restores the previous exception handler5
set_error_handler()Sets a user-defined function to handle errors4
set_exception_handler()Sets a user-defined function to handle exceptions5
trigger_error()Creates a user-defined error message4
user_error()Alias of trigger_error()4

No comments:

Post a Comment