How to capture fatal error errors in PHP

Source: Internet
Author: User
Tags exception handling php exception handling
This article mainly introduces the method of capturing Fatal error errors in PHP, using register_shutdown_function to catch Fatal error errors, the need for friends can refer to the Fatal error is generally not required to capture, But in a complex program, if the occasional memory shortage causes fatal error is difficult to deal with. Like what. Fatal error out in the MySQL class when the fetch. It's difficult to pinpoint the real problem at this time. PHP exception handling can be captured by Set_error_handler. But can only catch notice/warning level of error, for E_error is powerless. Register_shutdown_function can solve the shortage of set_error_handler. By registering the program end callback function with this function, you can catch errors that are not normally captured. Then the error is judged by Error_get_last.     It's easy to find a problem that's difficult to locate. The code is as follows:
function shutdown_function ()  
{  
    $e = Error_get_last ();    
    Print_r ($e);
Register_shutdown_function (' shutdown_function ');  


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.