Methods for capturing Fatalerror in PHP

Source: Internet
Author: User
Tags php exception handling
: This article describes how to capture the Fatalerror in PHP. if you are interested in the PHP Tutorial, refer to it. This article mainly introduces how to capture the Fatal error in PHP. you can use register_shutdown_function to capture the Fatal error. For more information, see

Fatal errors do not need to be captured, but in a complicated program, it is difficult to handle fatal errors due to memory insufficiency.

For example, when fatal error is fetch in the MySQL class, it is difficult to locate the real problem.

In PHP exception handling, you can use set_error_handler to capture. However, you can only capture NOTICE/WARNING-level errors. E_ERROR is powerless.

Register_shutdown_function can solve the problem of set_error_handler.

You can use this function to register the callback function for program termination to capture common errors that cannot be captured. then, you can use error_get_last to determine the errors. This makes it easy to locate difficult problems.

The code is as follows:


Function shutdown_function ()
{
$ E = error_get_last ();
Print_r ($ e );
}
Register_shutdown_function ('shutdown _ function ');

The above describes how to capture the Fatal error in PHP, including some content. I hope my friends who are interested in the PHP Tutorial can help me.

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.