Today found in PHP, if you want to record fatal error, you can use a good function,
Called Register_shutdown_function, summary as follows:
Register_shutdown_function allows us to set a second function that can be invoked when execution is closed. That is, our function will be invoked when our script executes or dies unexpectedly, causing PHP execution to close. So, 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 PHP closes the callback function to check whether the script is complete or not. If our variable is still false, we know that the last line of the script has not been executed, so it must have been executed at the execution of the program;
Examples are as follows:
- ? php
- $clean = false;
- function Shutdown_func () {
- Global $clean;
- if (! $clean) {
- Die ("Not a clean shutdown");
- }
- return false;
- }
- Register_shutdown_function ("Shutdown_func");
- $a = 1;
- $a = new Fooclass (); will fail because of a fatal error
- $clean = true;
- ?>
- One more example of recording fatal error
- function Catch_fatal_error ()
- {
- $last _error = Error_get_last ();
- Check to see if it belongs to Fatal_error
- if (isset ($last _error[' type ']) && $last _error[' type ']==e_error)
- {
- Related processing
- }
- }
- Register_shutdown_function (' Catch_fatal_error ');
Note that;
The 1,register_shutdown_function () function can be called repeatedly, but the order of execution is the same as the order of registration
2, if there is an exit () function call before the Register_shutdown_function () function is invoked, the register_shutdown_function () function will not execute
Support for registration function parameter passing after 3,PHP4
4, in some service terminals, such as Apache, the current directory can be changed in the Register_shutdown_function () function
5,register_shutdown_function () function executes after headers is sent
This article links http://www.cxybl.com/html/wlbc/Php/20130318/37221.html