Example of using PHP register_shutdown_function () function, shutdown function
With the Register_shutdown_function method, we can set up another function that can be called when execution is closed.
That is, our function is called when our script executes or the accidental death causes PHP execution to close.
"Use Scene"
① page is forced to stop (user)
② program code terminated unexpectedly or timed out
There is no destructor in ③PHP4, you can use this function to simulate destructors
shutdown.php
Copy the Code code as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");
Class shutdown{
Public Function Endscript () {
if (Error_get_last ()) {
Echo '
';
Print_r (Error_get_last ());
Echo '
';
}
File_put_contents (' D:\practise\php\Error\error.txt ', ' This is a test ');
Die (' End of script ');
}
}
Register_shutdown_function (Array (new shutdown (), ' endscript '));
Error test
Echo Md6 ();
Execute, Output:
Copy the Code code as follows:
( ! ) Fatal error:call to undefined function md6 () inch D:\practise\php\Error\shutdown.php on line 18
Array
(
[Type] = 1
[Message] = call to undefined function md6 ()
[File] = D:\practise\php\Error\shutdown.php
[Line] = 18
)
End of script
Copy the Code code as follows:
D:\practise\php\Error\error.txt:
This is a test
Note: The Register_shutdown_function method is called from memory, so the first parameter must use an absolute path when using the File_put_contents method.
http://www.bkjia.com/PHPjc/1021089.html www.bkjia.com true http://www.bkjia.com/PHPjc/1021089.html techarticle using the PHP register_shutdown_function () Function example, the shutdown function through the Register_shutdown_function method allows us to set another one that can be called when execution is closed ...