This article mainly introduces the PHP error handling function Register_shutdown_function Use example, the need for friends can refer to the following
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 ().
Can be called multiple times register_shutdown_function()
, 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 the execution of our script or accidental death causes PHP execution to close, and 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 Reporting error_reporting (0);//implement your own error message to show Register_shutdown_function (' Myshutdown '); $debug = True;function Myshutdown () { global $debug; Whether or not the error occurs, this sentence will execute Echo ' error ', ' <br/> '; if (! $debug) { $error = Error_get_last (); Todo can do a mail send alert or error log collection Var_export ($error) here;} }
DEMO2
Back to function with parameters: Log 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