When the program is running online, if you encounter a bug, want to not output error messages in the front end, but also timely email to inform the developer, Register_shutdown_function function can come in handy.
Registers a function that will be called after script execution completes or exit ().
Register_shutdown_function () can be called multiple times , and these registered callbacks are called sequentially in the order in which they were registered. If you call exit () inside a registered method , all processing is aborted, and the other registered abort callbacks are no longer called.
register_shutdown_function function, our function will be called when our script executes or the accidental death causes PHP execution to close, we can use it with Error_get_last to get the error message.
register_shutdown_function(Callable$callback[,Mixed $parameter[,Mixed$...] ]) callable callback function parameter can pass arguments to the abort function by passing in additional parameters DEMO1:
//Turn off Error reportingerror_reporting(0);//implement your own error message displayregister_shutdown_function(' Myshutdown ');$debug=true;functionMyshutdown () {Global $debug; //Whether or not the error occurred, this sentence will be executed Echo' ERROR ', ' <br/> '; if(!$debug) { $error=Error_get_last (); //Todo can do email reminders or error log collection here Var_export($error); }}
DEMO2
//back to function with parameters: Record the current request URL$current _page=Htmlspecialchars($_server[' Script_name '], ent_quotes, ' UTF-8 ');$current _page.=$_server[' Query_string ']? ‘?‘.Htmlspecialchars($_server[' Query_string '], ent_quotes, ' UTF-8 '): ';register_shutdown_function(function($current _page) { //todo send email or log},$current _page);Error_get_last ()
Error message View:http//php.net/manual/zh/errorfunc.constants.php
PHP error handling function register_shutdown_function