6.x core.php hook_boot()
7.x system.api.php hook_boot()

Perform setup tasks for all page requests.

This hook is run at the beginning of the page request. It is typically used to set up global parameters that are needed later in the request.

Only use this hook if your code must run even for cached page views. This hook is called before the theme, modules, or most include files are loaded into memory. It happens while Drupal is still in bootstrap mode.

See also


Related topics

1 string reference to 'hook_boot'
system_test_boot in modules/simpletest/tests/system_test.module
Implements hook_boot().
4 functions implement hook_boot()

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

boot_test_1_boot in modules/simpletest/tests/boot_test_1.module
Implements hook_boot().
locale_test_boot in modules/locale/tests/locale_test.module
Implements hook_boot().
session_test_boot in modules/simpletest/tests/session_test.module
Implements hook_boot().
system_test_boot in modules/simpletest/tests/system_test.module
Implements hook_boot().
2 invocations of hook_boot()
_drupal_bootstrap_page_cache in includes/bootstrap.inc
Attempts to serve a page from the cache.
_drupal_bootstrap_page_header in includes/bootstrap.inc
Invokes hook_boot(), initializes locking system, and sends HTTP headers.


modules/system/system.api.php, line 1875
Hooks provided by Drupal core and the System module.


function hook_boot() {

  // We need user_access() in the shutdown function. Make sure it gets loaded.
  drupal_load('module', 'user');


dalin’s picture

For those interested, it gets called during DRUPAL_BOOTSTRAP_PAGE_HEADER

roderik’s picture

Do not invoke any module from within hook_boot(). (This includes calling functions that invoke hooks, e.g. drupal_get_normal_path().) Doing this can 'pollute' the information cached by module_implements(), with lasting effects.

Specifically: if hook_boot() invokes any other hook while the module_implements() cache is empty, many invocations of that hook are not seen. Because the info is cached at that time, these invocations will never be called, until the next time the cache is cleared.

See Issue #496170.

dragon658’s picture

If you want to call a function on every page request, you also can look at hook hook_page_alter.

osopolar’s picture

Execution order:

index.php > drupal_bootstrap() > _drupal_bootstrap_page_cache(), BTW: here hook_boot() and hook_exit() gets invoked here too > drupal_serve_page_from_cache() > Print the page: print $cache->data['body'].

bleen’s picture