This article mainly introduces the method of capturing Fatal error in PHP. Use register_shutdown_function to capture Fatal error. Friends in need can refer to it
Fatal error generally does not need to be captured, but in a complex program, if Fatal errors caused by occasional insufficient memory are difficult to handle. For example, fatal errors occur when fetching in the MySQL class. At this time, it is difficult to locate the real problem.
PHP exception handling can Capture through set_error_handler. However, it can only capture NOTICE/WARNING level errors, and it is powerless for E_ERROR.
register_shutdown_function can solve the shortcomings of set_error_handler.
Register the program end callback function through this function, and you can Capture errors that cannot be caught normally. Then use error_get_last to judge the errors. It is easy to find problems that are difficult to locate.
Copy the code
The code is as follows:function shutdown_function() {
$e = error_get_last(); print_r($e);
}
register_shutdown_function('shutdown_function');
The above introduces the method of catching Fatal error in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.