4.6.x core.php hook_init()
4.7.x core.php hook_init()
5.x core.php hook_init()
6.x core.php hook_init()
7.x system.api.php hook_init()

Perform setup tasks.

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. If you have code which must run once on all non cached pages, use hook_menu(!$may_cache) 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. The usual fix is to move your code to hook_menu(!$may_cache).

Return value


Related topics

5 functions implement hook_init()

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

conf_init in includes/bootstrap.inc
Locate the appropriate configuration file.
module_init in includes/module.inc
Initialize all modules.
tablesort_init in includes/tablesort.inc
Initialize the table sort context.
variable_init in includes/bootstrap.inc
Load the persistent variable table.
xtemplate_init in themes/engines/xtemplate/xtemplate.engine
2 invocations of hook_init()
drupal_page_header in includes/bootstrap.inc
Set HTTP headers in preparation for a page response.
module_init in includes/module.inc
Initialize all modules.


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


function hook_init() {
  global $recent_activity;

  if ((variable_get('statistics_enable_auto_throttle', 0)) && 
    (!rand(0, variable_get('statistics_probability_limiter', 9)))) {

    $throttle = throttle_status();
    // if we're at throttle level 5, we don't do anything
    if ($throttle < 5) {
      $multiplier = variable_get('statistics_throttle_multiplier', 60);
      // count all hits in past sixty seconds
      $result = db_query('SELECT COUNT(timestamp) AS hits FROM
        {accesslog} WHERE timestamp >= %d', (time() - 60));
      $recent_activity = db_fetch_array($result);