This will allow you to have a function called after your script has finished execution (via exit, die, or any method). Name the function to be called and optionally give any necessary parameters.

You may set any number of functions and they will be called in the order they were set. In these examples we’re just printing out some text but your shutdown functions can do anything they could do normally.

echo 'Code goes here';
 
register_shutdown_function( 'alternateEnding' );
 
echo ' ...and more code if you want.';
 
register_shutdown_function( 'theEnd', 'bye', 'Tuesday' );
 
function theEnd( $str1, $str2 ) {
  echo "\n\nThis is the end.\nI just wanted to say $str1 before $str2";
}
 
function alternateEnding() {
  echo "\n\nWait there's more...";
}
/*
Code goes here ...and more code if you want.
 
Wait there's more...
 
This is the end.
I just wanted to say bye before Tuesday
*/