Usage of register_shutdown_function function in php
Jul 25, 2016 am 08:57 AM
This article shares the usage of the PHP function register_shutdown_function for reference by friends in need.
The usage of php function register_shutdown_function is as follows: <?php function shutdown() { $last_error = error_get_last(); if ($last_error) { error_log(print_r($last_error, true), 3, ERROR_LOG); } } register_shutdown_function('shutdown'); ?> Copy after login Instructions: When the php script dies, you don't want to display a fatal error or a blank page to the user (when display_errors is set to off). There is a function in PHP called register_shutdown_function that allows us to set another function that can be called when execution is shut down. This function will be called when the script execution is completed or unexpectedly dies, causing PHP execution to be shut down. Therefore, we can use the method of setting a variable to false at the beginning of the script, and then setting it to true at the end of the script, so that The PHP shutdown callback function checks whether the script is complete. If our variable is still false, we know that the last line of the script was not executed, so it must have died somewhere in the program execution. The above example demonstrates how to give the user some appropriate feedback when a fatal error needs to be displayed. You can turn off the display of fatal errors (Annotation: you can set display_errors and error_reporting). |

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
