PHP Functions - Session_Register_Shutdown()
PHP allows you to register shutdown functions using session_register_shutdown(). These callbacks are executed once the script execution completes or exit() is called. Multiple shutdown functions can be registered and they will be called in the order of registration.
This function accepts an optional number of arguments. Arguments must be separated by commas. The function returns TRUE if successful or FALSE on failure.
The read callback returns a string in the same format that the data was sent for storage via the write callback. This value will be unserialized by PHP and populated in the $_SESSION superglobal.
Note that the read and close callbacks do not get invoked if the PHP process is killed with a SIGTERM or SIGKILL signal. The close callback will however be invoked if the script fails to exit() properly.
It is important to understand the difference between a variable and an argument because PHP does not use strict types (see PHP’s weak typing for more info). Therefore, if you pass an integer to this function as an argument it will be interpreted as a string and you will run into the error Uncaught TypeError: argument passed to function must be of type int instead of boolean, int given.
The php function session_register_shutdown() can be used in conjunction with the php function session_write_close() to allow you to execute custom actions at the end of your web application’s script. I have found this to be very useful in a few of my projects because the current working directory may change within my shutdown function on some web servers like Apache.