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

Perform setup tasks. See also, hook_init.

This hook is run at the beginning of the page request. It is typically used to set up global parameters which 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 modules or most include files are loaded into memory. It happens while Drupal is still in bootstrap mode.

Return value


Related topics

1 invocation of hook_boot()
system_performance_settings in modules/system/system.admin.inc
Form builder; Configure site performance settings.


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


function hook_boot() {

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


jjeff’s picture

hook_boot() gets called during the DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE phase of the bootstrap process (see drupal_bootstrap()).

By this time the following phases have already happened: DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION. This means that you have access to the database and session information.

However, the following phases happen after hook_boot(): DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL. This means that you do not have access to language functions, path functions (such as path aliasing), or any of the functions in common.inc.

hook_boot() is the first hook to get run during a page request. It's great if you want to get into the page request very early and execute code before Drupal does its complete bootstrap. However it runs even with normal page caching turned on, so usually hook_init() is a better solution if you want to get in early, but you're okay with a full bootstrap of Drupal happening. Also note that modules which implement hook_boot() will show up as "incompatible with aggressive mode caching and will not function properly" on the admin/settings/performance page.

yuriy.babenko’s picture

It's important to note that your hook_boot() will not get called unless your module is set to bootstrap=1 in the {system} table. I believe this flag is set when you install the module.

aklump’s picture

In Drupal 6 (not sure about 7), I found that if I add hook_boot() to a module under development, after it's already been added to the system table, then I have to manually update {system}.bootstrap to 1 in order to get it my hook_boot() to be called. Simply disabling/enabling, or uninstalling/reinstalling doesn't switch that field from a 0 to a 1.

Another thing to note (again D6) is that if you try to call module_invoke_all('some_hook_name') from hook_boot() and the module implementing 'some_hook_name' is not part of the bootstrap module list, the hook function will NOT be found.

vkareh’s picture

Keep in mind when adding hook_boot() to your module as it may automatically set {system}.bootstrap=1 even when the module was already enabled.

barobba’s picture

After adding hook_boot() to your module, you might need to go to "/admin/build/modules/list" to refresh the "system" table.

eltermann’s picture

For this purpose, drush pm-list (or just drush pml) also works.

confiq’s picture

How Can i refresh after hook_update?

voj’s picture

Take note that you cannot use API of other module in hook_boot because some of the modules are not yet finished loading.