function drush_bootstrap

8.0.x drush_bootstrap($phase, $phase_max = FALSE)
6.x drush_bootstrap($phase, $phase_max = FALSE)
7.x drush_bootstrap($phase, $phase_max = FALSE)
3.x drush_bootstrap($phase)
4.x drush_bootstrap($phase, $phase_max = FALSE)
5.x drush_bootstrap($phase, $phase_max = FALSE)
master drush_bootstrap($phase, $phase_max = FALSE)

Bootstrap Drush to the desired phase.

This function will sequentially bootstrap each lower phase up to the phase that has been requested.


int $phase: The bootstrap phase to bootstrap to.

int $phase_max: (optional) The maximum level to boot to. This does not have a use in this function itself but can be useful for other code called from within this function, to know if e.g. a caller is in the process of booting to the specified level. If specified, it should never be lower than $phase.

Return value

bool TRUE if the specified bootstrap phase has completed.

See also


8 calls to drush_bootstrap()
BrowseCommands::browse in lib/Drush/CommandFiles/core/BrowseCommands.php
Display a link to a given path or open link in a browser.
drush_bootstrap_max in includes/
Bootstrap to the highest level possible, without triggering any errors.
drush_bootstrap_to_phase in includes/
Bootstrap to the specified phase.
drush_core_pre_site_install in commands/core/
Perform setup tasks for installation.
drush_user_login in commands/user/
Displays a one time login link for the given user.

... See full list


includes/, line 196


function drush_bootstrap($phase, $phase_max = FALSE) {
  $bootstrap = \Drush::bootstrap();
  $phases = _drush_bootstrap_phases(TRUE);
  $result = TRUE;

  // If the requested phase does not exist in the list of available
  // phases, it means that the command requires bootstrap to a certain
  // level, but no site root could be found.
  if (!isset($phases[$phase])) {
    $result = drush_bootstrap_error('DRUSH_NO_SITE', dt("We could not find an applicable site for that command."));

  // Once we start bootstrapping past the DRUSH_BOOTSTRAP_DRUSH phase, we
  // will latch the bootstrap object, and prevent it from changing.
  if ($phase > DRUSH_BOOTSTRAP_DRUSH) {

  drush_set_context('DRUSH_BOOTSTRAPPING', TRUE);
  foreach ($phases as $phase_index => $current_phase) {
    $bootstrapped_phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE', -1);
    if ($phase_index > $phase) {
    if ($phase_index > $bootstrapped_phase) {
      if ($result = drush_bootstrap_validate($phase_index)) {
        if (method_exists($bootstrap, $current_phase) && !drush_get_error()) {
          drush_log(dt("Drush bootstrap phase : !function()", array('!function' => $current_phase)), LogLevel::BOOTSTRAP);

          // Reset commandfile cache and find any new command files that are available during this bootstrap phase.
          _drush_find_commandfiles($phase_index, $phase_max);
        drush_set_context('DRUSH_BOOTSTRAP_PHASE', $phase_index);
  drush_set_context('DRUSH_BOOTSTRAPPING', FALSE);
  if (!$result || drush_get_error()) {
    $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array());
    foreach ($errors as $code => $message) {
      drush_set_error($code, $message);
  return !drush_get_error();