4.6.x core.php hook_exit($destination = NULL)
4.7.x core.php hook_exit($destination = NULL)
5.x core.php hook_exit($destination = NULL)
6.x core.php hook_exit($destination = NULL)
7.x system.api.php hook_exit($destination = NULL)

Perform cleanup tasks.

This hook is run at the end of most regular page requests. It is often used for page logging and specialized cleanup. This hook MUST NOT print anything because by the time it runs the response is already sent to the browser.

Only use this hook if your code must run even for cached page views. If you have code which must run once on all non cached pages, use hook_init instead. Thats the usual case. If you implement this hook and see an error like 'Call to undefined function', it is likely that you are depending on the presence of a module which has not been loaded yet. It is not loaded because Drupal is still in bootstrap mode.


$destination: If this hook is invoked as part of a drupal_goto() call, then this argument will be a fully-qualified URL that is the destination of the redirect. Modules may use this to react appropriately; for example, nothing should be output in this case, because PHP will then throw a "headers cannot be modified" error when attempting the redirection.

Return value


Related topics

2 functions implement hook_exit()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

statistics_exit in modules/statistics/statistics.module
Implementation of hook_exit().
throttle_exit in modules/throttle/throttle.module
Implementation of hook_exit().
3 invocations of hook_exit()
drupal_goto in includes/common.inc
Send the user to a different Drupal page.
drupal_page_footer in includes/common.inc
Perform end-of-request tasks.
system_performance_settings in modules/system/system.admin.inc
Form builder; Configure site performance settings.


developer/hooks/core.php, line 518
These are the hooks that are invoked by the Drupal core.


function hook_exit($destination = NULL) {
  db_query('UPDATE {counter} SET hits = hits + 1 WHERE type = 1');


KhaledBlah’s picture

It should be noted that this hook will not be called during cron runs triggered by cron.php while it will be executed during cron triggered "manually" (e.g. through the link provided in the admin UI). Maybe this will help someone save some time :-).

Karol Haltenberger’s picture

If a module implements hook_boot or hook_exit, their bootstrap bit gets set to 1 by module_rebuild_cache, which - unless I'm wrong - loads them during bootstrap, when even core drupal functions may be unavailable, so using them outside of your functions can cause a WSOD.

fgm’s picture

Note that when using Pressflow 6 instead of base Drupal 6, drupal_set_mesage() and similar functions like dsm()/dpm() do not work in implementations of this hook because it is invoked once the session has already been committed() and these functions work by adding data to the session, which is closed at this point. Compare Drupal 6 vs Pressflow 6 implementations of drupal_page_footer for details.