function drupal_bootstrap

Ensures Drupal is bootstrapped to the specified phase.

In order to bootstrap Drupal from another PHP script, you can use this code:

define('DRUPAL_ROOT', '/path/to/drupal');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Parameters

int $phase: A constant telling which phase to bootstrap to. When you bootstrap to a particular phase, all earlier phases are run automatically. Possible values:

boolean $new_phase: A boolean, set to FALSE if calling drupal_bootstrap from inside a function called from drupal_bootstrap (recursion).

Return value

int The most recently completed phase.

16 calls to drupal_bootstrap()
authorize.php in drupal/authorize.php
Administrative script for running authorized file operations.
cron.php in drupal/cron.php
Handles incoming requests to fire off regularly-scheduled tasks (cron jobs).
drupal_get_bootstrap_phase in drupal/includes/bootstrap.inc
Returns the current bootstrap phase for this Drupal process.
drupal_theme_initialize in drupal/includes/theme.inc
Initializes the theme system by loading the theme.
http.php in drupal/modules/simpletest/tests/http.php
Fake an HTTP request, for use during testing.

... See full list

File

drupal/includes/bootstrap.inc, line 2469
Functions that need to be loaded on every Drupal request.

Code

function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {

  // Not drupal_static(), because does not depend on any run-time information.
  static $phases = array(
    DRUPAL_BOOTSTRAP_CONFIGURATION,
    DRUPAL_BOOTSTRAP_PAGE_CACHE,
    DRUPAL_BOOTSTRAP_DATABASE,
    DRUPAL_BOOTSTRAP_VARIABLES,
    DRUPAL_BOOTSTRAP_SESSION,
    DRUPAL_BOOTSTRAP_PAGE_HEADER,
    DRUPAL_BOOTSTRAP_LANGUAGE,
    DRUPAL_BOOTSTRAP_FULL,
  );

  // Not drupal_static(), because the only legitimate API to control this is to
  // call drupal_bootstrap() with a new phase parameter.
  static $final_phase;

  // Not drupal_static(), because it's impossible to roll back to an earlier
  // bootstrap state.
  static $stored_phase = -1;
  if (isset($phase)) {

    // When not recursing, store the phase name so it's not forgotten while
    // recursing but take care of not going backwards.
    if ($new_phase && $phase >= $stored_phase) {
      $final_phase = $phase;
    }

    // Call a phase if it has not been called before and is below the requested
    // phase.
    while ($phases && $phase > $stored_phase && $final_phase > $stored_phase) {
      $current_phase = array_shift($phases);

      // This function is re-entrant. Only update the completed phase when the
      // current call actually resulted in a progress in the bootstrap process.
      if ($current_phase > $stored_phase) {
        $stored_phase = $current_phase;
      }
      switch ($current_phase) {
        case DRUPAL_BOOTSTRAP_CONFIGURATION:
          _drupal_bootstrap_configuration();
          break;
        case DRUPAL_BOOTSTRAP_PAGE_CACHE:
          _drupal_bootstrap_page_cache();
          break;
        case DRUPAL_BOOTSTRAP_DATABASE:
          _drupal_bootstrap_database();
          break;
        case DRUPAL_BOOTSTRAP_VARIABLES:
          _drupal_bootstrap_variables();
          break;
        case DRUPAL_BOOTSTRAP_SESSION:
          require_once DRUPAL_ROOT . '/' . variable_get('session_inc', 'includes/session.inc');
          drupal_session_initialize();
          break;
        case DRUPAL_BOOTSTRAP_PAGE_HEADER:
          _drupal_bootstrap_page_header();
          break;
        case DRUPAL_BOOTSTRAP_LANGUAGE:
          drupal_language_initialize();
          break;
        case DRUPAL_BOOTSTRAP_FULL:
          require_once DRUPAL_ROOT . '/includes/common.inc';
          _drupal_bootstrap_full();
          break;
      }
    }
  }
  return $stored_phase;
}