Through the register_shutdown_function method, we can set another function that can be called when the execution is shut down.
That is to say, our function will be called when our script execution is completed or when the php execution is about to be shut down due to unexpected death.
【Usage Scenario】
① The page was forced to stop by (user)
② The program code terminates unexpectedly or times out
③ There is no destructor in php4, you can use this function to simulate the destructor
shutdown.php
Copy code The code is as follows:
header("content-type:text/html;charset=utf-8");
class Shutdown{
Public function endScript(){
If(error_get_last()){
echo '
';<br> print_r(error_get_last());<br> echo '';
register_shutdown_function(array(new Shutdown(), 'endScript'));
//Error testing
echo md6();
Execution, output:
Copy code The code is as follows:
( ! ) Fatal error: Call to undefined function md6() in D:practisephpErrorshutdown.php on line 18
Array
(
[type] => 1
[message] => Call to undefined function md6()
[file] => D:practisephpErrorshutdown.php
[line] => 18
)
End of script
Copy code The code is as follows:
D:practisephpErrorerror.txt:
this is a test
Note: The register_shutdown_function method is called from memory, so when using the file_put_contents method, the first parameter must use an absolute path.