Sorry, you need to enable JavaScript to visit this website.

What are shut down functions in php?

Submitted by abhaisasidharan on Fri, 09/03/2021 - 10:43

Shutdown functions are functions that are executed after the current scope has been "shutdown". Say, you want to run a function after another function has completed execution, then this is the way to go. It is also a way to make PHP web requests somewhat asynchronous. In a Drupal context, say you are sending a request, that triggers a function. But you do not want to wait for the response or you want the function to start executing after the request has returned a response. All you have to do is register a shutdown function within the function you are triggering using the request. Say you have a Drupal controller with the function page(). Inside this function call drupal_register_shutdown_function("yourfunction"). The function "yourfunction" will start execution after page() has completed execution.

PHP example:

function shutdown()
    // This is our shutdown function, this
    // function will be executed when the php
    // file completes execution.

    echo 'Script executed with success', PHP_EOL;