Introduction
PHP provides error handling and logging functions. These functions allow you to define your own error handling rules and modify error recording methods. In this way, you can change and enhance the error output information according to your needs To meet actual needs.
Through the logging function, you can send information directly to other log servers, or to a designated email address (or send it through a mail gateway), or to operating system logs, etc., so you have options The most important part of logging and monitoring your applications and websites.
The error reporting function allows you to customize the level and type of error feedback, which can be a simple prompt message or use a custom function to process and return information.
Example
Below we can see the error handling function in PHP Examples of usage. We define an error handling function, log error information to a file (using XML format), and send an email to the developer when a serious logic error occurs.
Example #1 Using error handles in scripts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
Error handling function
debug_backtrace — Generate a backtrace
debug_print_backtrace — Print a backtrace.
error_get_last — Get the last error that occurred
error_log — Send error information to somewhere
error_reporting — Set what kind of PHP errors should be reported
restore_error_handler — Restore the previous error handling function
restore_exception_handler — Restore the previously defined one Exception handling function.
set_error_handler — Set a user-defined error handling function
set_exception_handler — Set a user-defined exception handling function.
trigger_error — Generate a user-level error/warning/notice message
user_error — Alias of trigger_error