What does register_shutdown_function do?
I have no understanding whatsoever on the usage of it and what it does.
I know you can use it and fit nicely with a custom error handler, but I don’t know what to pass through it, what to do with it, etc.
Could someone explain it in the easiest terms for this coding newbie?
This is actually a pretty simple function. So you have a php script:
Basically what happens is your script runs and when it’s finished because we added this line
register_shutdown_function('endScript');it will call the function endScript and finally outputMy little script has finished.Here’s a little extra from the documentation:
*Update
A great use for it is when you frequently use the function called
exit()in php.For example:
Now notice that even though you call exit multiple times you don’t have to call the
endScriptfunction before exit each time. You registered it in the begining and now you know that if you ever exit or your script finishes then your function is called.Now of course my shutdown function is pretty useless; but it can become useful if you need to clean things (ie. Close open file handles, save some persistent data, etc)