drupal_register_shutdown_function

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 &drupal_register_shutdown_function($callback = NULL)

Register 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".

Parameters

$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

register_shutdown_function()

Related topics

▾ 13 functions call drupal_register_shutdown_function()

DrupalWebTestCase::setUp in modules/simpletest/drupal_web_test_case.php
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
DrupalWebTestCase::tearDown in 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 includes/common.inc
Executes a cron run when called.
hook_boot in modules/system/system.api.php
Perform setup tasks for all page requests.
menu_cache_clear in includes/menu.inc
Clears the cached cached data for a single named menu.
search_cron in modules/search/search.module
Implements hook_cron().
system_test_page_shutdown_functions in modules/simpletest/tests/system_test.module
A simple page callback which adds a register shutdown function.
_batch_page in includes/batch.inc
State-based dispatcher for the batch processing page.
_drupal_session_read in includes/session.inc
Reads an entire session from the database (internal use only).
_drupal_shutdown_function in includes/bootstrap.inc
Internal function used to execute registered shutdown functions.
_lock_id in includes/lock.inc
Helper function to get this request's unique id.
_menu_clear_page_cache in includes/menu.inc
Helper function to clear the page and block caches at most twice per page load.
_system_test_first_shutdown_function in modules/simpletest/tests/system_test.module
Dummy shutdown function which registers another shutdown function.

Code

includes/bootstrap.inc, line 3203

<?php
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)) {
      register_shutdown_function('_drupal_shutdown_function');
    }
    $args = func_get_args();
    array_shift($args);
    // Save callback and arguments
    $callbacks[] = array(
      'callback' => $callback,
      'arguments' => $args,
    );
  }
  return $callbacks;
}
?>