function drupal_register_shutdown_function

7.x &drupal_register_shutdown_function($callback = NULL)

Registers a function for execution on shutdown.

Wrapper for register_shutdown_function() that catches thrown exceptions to avoid "Exception thrown without a stack frame in Unknown".


$callback: The shutdown function to register.

...: Additional arguments to pass to the shutdown function.

Return value

Array of shutdown functions to be executed.

See also


Related topics

13 calls to drupal_register_shutdown_function()
DrupalWebTestCase::prepareEnvironment in drupal/modules/simpletest/drupal_web_test_case.php
Prepares the current environment for running the test.
DrupalWebTestCase::tearDown in drupal/modules/simpletest/drupal_web_test_case.php
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
drupal_cron_run in drupal/includes/
Executes a cron run when called.
hook_boot in drupal/modules/system/system.api.php
Perform setup tasks for all page requests.
menu_cache_clear in drupal/includes/
Clears the cached cached data for a single named menu.

... See full list


drupal/includes/, line 3371
Functions that need to be loaded on every Drupal request.


function &drupal_register_shutdown_function($callback = NULL) {
  // We cannot use drupal_static() here because the static cache is reset during
  // batch processing, which breaks batch handling.
  static $callbacks = array();

  if (isset($callback)) {
    // Only register the internal shutdown function once.
    if (empty($callbacks)) {
    $args = func_get_args();
    // Save callback and arguments
    $callbacks[] = array(
      'callback' => $callback,
      'arguments' => $args,
  return $callbacks;