register_shutdown_function()
register_shutdown_function() — Register a function for execution on shutdown.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Registers a callback to be executed after script execution finishes or exit() is called.
Signature
register_shutdown_function(callable $callback, mixed ...$args): void
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $callback | callable | The shutdown callback to register. |
| ...$args | mixed | It is possible to pass parameters to the shutdown function by passing additional parameters. |
Return value
No value is returned.
Example
A runnable snippet:
function shutdown() { // This is our shutdown function, in // here we can do any last operations // before the script is complete. echo 'Script executed with success', PHP_EOL; } register_shutdown_function('shutdown');
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page register_shutdown_function() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.