Skip to content

Instantly share code, notes, and snippets.

@angry-dan
Created April 16, 2015 10:27
Show Gist options
  • Save angry-dan/3be674934911eb5ceace to your computer and use it in GitHub Desktop.
Save angry-dan/3be674934911eb5ceace to your computer and use it in GitHub Desktop.
Benchmark the Drupal bootstrap phases. Since this is something that happens on every page load it needs to be really fast. You should probably be worried if bootstrap is taking more than 300ms per page load.
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$phases = array(
'CONFIGURATION' => DRUPAL_BOOTSTRAP_CONFIGURATION,
'PAGE_CACHE' => DRUPAL_BOOTSTRAP_PAGE_CACHE,
'DATABASE' => DRUPAL_BOOTSTRAP_DATABASE,
'VARIABLES' => DRUPAL_BOOTSTRAP_VARIABLES,
'SESSION' => DRUPAL_BOOTSTRAP_SESSION,
'PAGE_HEADER' => DRUPAL_BOOTSTRAP_PAGE_HEADER,
'LANGUAGE' => DRUPAL_BOOTSTRAP_LANGUAGE,
'FULL' => DRUPAL_BOOTSTRAP_FULL,
);
timer_start('complete_run');
foreach ($phases as $id => $phase) {
timer_start('bootstrap_' . $id);
drupal_bootstrap($phase);
$t = timer_stop('bootstrap_' . $id);
echo $id . ': ' . $t['time'] . '<br />';
}
$t = timer_stop('complete_run');
echo "<br />TOTAL: " . $t['time'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment