The PHP Function Register_Shutdown_Function()
The php function register_shutdown_function() can be useful for software developers. It allows you to register a shutdown function that will be executed when the script execution ends or when the php function exit() is called.
You can also use it to handle unexpected termination of your script - like a timeout for instance. In this case you might want to print a "Done!" or something else when the script terminates, for example because it reached its time limit. Normally when this happens you would get an error message like "Execution time of 20 seconds exceeded in — line XX."
Using the shutdown function you can avoid this, you just register the shutdown function near the beginning of your script and when the timeout occurs it will execute the shutdown function automatically. This can be useful if you want to do things like cleanup, log errors, display HTML or something similar.
PHP also has some other handy functions for handling error situations, such as the set_error_handler() and the set_exception_handler(). However, these only allow you to catch and log the basic errors. If you want to log fatal errors or something like that you need a tool such as the register_shutdown_function() - fortunately there is also a library that handles this for you.
For more information on PHP check out Hacking with PHP - the book that gets you up and running fast. Get started with 1200+ hands-on pages of PHP learning today.