The use of register_shutdown_function functions in PHP

Source: Internet
Author: User
This article shares the use of PHP function register_shutdown_function, with the need for a friend reference.

The use of PHP function register_shutdown_function is as follows:

     
     

Description: When the PHP script dies, you do not want to show the user a fatal error or a blank page (in case the display_errors is set to OFF). There is a function called Register_shutdown_function in PHP that lets us set up another function that can be called when execution is closed. This function will be called when the execution of the script completes or the unexpected death causes PHP execution to close. So, we can use a method that sets a variable to false at the beginning of the script and then sets it to true at the end of the script, so that the PHP shutdown callback function checks whether the script is complete or not. If our variable is still false, we know that the last line of the script is not executed, so it must be executed at the execution of the program. The above example shows how to give the user some appropriate feedback when a fatal error needs to be displayed. You can set display_errors and error_reporting by turning off the display of fatal errors.

  • 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.