In some cases, we need to do some follow-up work at the end of the program execution, and this time, PHP's register_shutdown_function function will help us to implement this function.
Introduction to Functions
When the PHP program executes, the Register_shutdown_function function is automatically executed, and the function requires a parameter that specifies who will handle the subsequent work. Among them, the execution of the program is completed, divided into the following situations:
First: An error occurred during the execution of the PHP code
The second type: PHP code successfully executed
Third: PHP code runs out of time
Fourth type: page is forced to stop by the user
Program Entry File Introduction
register_shutdown_function (array(' Error ', ' systemerror '));
Error class source code
<?PHPclasserror{ Public Static functionSystemerror () {$message= ' '; if($error=Error_get_last ()) { $separator= "\ r \ n"; $date=Date(' Y-m-d h:i:s ', Time()); $message.= "[".$date."] ---message: ".$error[' Message '].$separator; $message. = "File:".$error[' File '].$separator; $message. = "line:".$error[' Line '].$separator; $url= ' '; $data=Array( ' Info ' =$message, ' type ' = ' BBS ' ); Helper:: Curlrequest ($url,$data,true, 5); }Else{ //Some other business logic is handled here } }}
Example of using PHP function register_shutdown_function