- Patch #622048 by sun: streamline drupal_bootstrap() and expose the flow to code profilers.
parent
5176bed85e
commit
373fee82b3
|
@ -782,14 +782,27 @@ function variable_del($name) {
|
||||||
* from a form submission, the contents of a shopping cart, or other user-
|
* from a form submission, the contents of a shopping cart, or other user-
|
||||||
* specific content that should not be cached and displayed to other users.
|
* specific content that should not be cached and displayed to other users.
|
||||||
*
|
*
|
||||||
|
* @param $check_only
|
||||||
|
* (optional) Set to TRUE to only return whether a previous call found a
|
||||||
|
* cache entry.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* The cache object, if the page was found in the cache, NULL otherwise.
|
* The cache object, if the page was found in the cache, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
function drupal_page_get_cache() {
|
function drupal_page_get_cache($check_only = FALSE) {
|
||||||
global $base_root;
|
global $base_root;
|
||||||
|
static $cache_hit = FALSE;
|
||||||
|
|
||||||
|
if ($check_only) {
|
||||||
|
return $cache_hit;
|
||||||
|
}
|
||||||
|
|
||||||
if (drupal_page_is_cacheable()) {
|
if (drupal_page_is_cacheable()) {
|
||||||
return cache_get($base_root . request_uri(), 'cache_page');
|
$cache = cache_get($base_root . request_uri(), 'cache_page');
|
||||||
|
if ($cache !== FALSE) {
|
||||||
|
$cache_hit = TRUE;
|
||||||
|
}
|
||||||
|
return $cache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,6 +811,7 @@ function drupal_page_get_cache() {
|
||||||
*
|
*
|
||||||
* @param $allow_caching
|
* @param $allow_caching
|
||||||
* Set to FALSE if you want to prevent this page to get cached.
|
* Set to FALSE if you want to prevent this page to get cached.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* TRUE if the current page can be cached, FALSE otherwise.
|
* TRUE if the current page can be cached, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
|
@ -1447,7 +1461,41 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
|
||||||
// phase.
|
// phase.
|
||||||
while ($phases && $phase > $completed_phase && $final_phase > $completed_phase) {
|
while ($phases && $phase > $completed_phase && $final_phase > $completed_phase) {
|
||||||
$current_phase = array_shift($phases);
|
$current_phase = array_shift($phases);
|
||||||
_drupal_bootstrap($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;
|
||||||
|
}
|
||||||
// This function is reentrant. Only update the completed phase when the
|
// This function is reentrant. Only update the completed phase when the
|
||||||
// current call actually resulted in a progress in the bootstrap process.
|
// current call actually resulted in a progress in the bootstrap process.
|
||||||
if ($current_phase > $completed_phase) {
|
if ($current_phase > $completed_phase) {
|
||||||
|
@ -1459,31 +1507,22 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current bootstrap phase for this Drupal process. The
|
* Bootstrap configuration: Setup script environment and load settings.php.
|
||||||
* current phase is the one most recently completed by
|
|
||||||
* drupal_bootstrap().
|
|
||||||
*
|
|
||||||
* @see drupal_bootstrap
|
|
||||||
*/
|
*/
|
||||||
function drupal_get_bootstrap_phase() {
|
function _drupal_bootstrap_configuration() {
|
||||||
return drupal_bootstrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
function _drupal_bootstrap($phase) {
|
|
||||||
global $conf, $user;
|
|
||||||
static $cache;
|
|
||||||
|
|
||||||
switch ($phase) {
|
|
||||||
|
|
||||||
case DRUPAL_BOOTSTRAP_CONFIGURATION:
|
|
||||||
drupal_environment_initialize();
|
drupal_environment_initialize();
|
||||||
// Start a page timer:
|
// Start a page timer:
|
||||||
timer_start('page');
|
timer_start('page');
|
||||||
// Initialize the configuration, including variables from settings.php.
|
// Initialize the configuration, including variables from settings.php.
|
||||||
drupal_settings_initialize();
|
drupal_settings_initialize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap page cache: Try to serve a page from cache.
|
||||||
|
*/
|
||||||
|
function _drupal_bootstrap_page_cache() {
|
||||||
|
global $user;
|
||||||
|
|
||||||
case DRUPAL_BOOTSTRAP_PAGE_CACHE:
|
|
||||||
// Allow specifying special cache handlers in settings.php, like
|
// Allow specifying special cache handlers in settings.php, like
|
||||||
// using memcached or files for storing cache information.
|
// using memcached or files for storing cache information.
|
||||||
require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');
|
require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');
|
||||||
|
@ -1522,9 +1561,12 @@ function _drupal_bootstrap($phase) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
case DRUPAL_BOOTSTRAP_DATABASE:
|
/**
|
||||||
|
* Bootstrap database: Initialize database system and register autoload functions.
|
||||||
|
*/
|
||||||
|
function _drupal_bootstrap_database() {
|
||||||
// The user agent header is used to pass a database prefix in the request when
|
// The user agent header is used to pass a database prefix in the request when
|
||||||
// running tests. However, for security reasons, it is imperative that we
|
// running tests. However, for security reasons, it is imperative that we
|
||||||
// validate we ourselves made the request.
|
// validate we ourselves made the request.
|
||||||
|
@ -1538,24 +1580,27 @@ function _drupal_bootstrap($phase) {
|
||||||
// Register autoload functions so that we can access classes and interfaces.
|
// Register autoload functions so that we can access classes and interfaces.
|
||||||
spl_autoload_register('drupal_autoload_class');
|
spl_autoload_register('drupal_autoload_class');
|
||||||
spl_autoload_register('drupal_autoload_interface');
|
spl_autoload_register('drupal_autoload_interface');
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap variables: Load system variables and all enabled bootstrap modules.
|
||||||
|
*/
|
||||||
|
function _drupal_bootstrap_variables() {
|
||||||
|
global $conf;
|
||||||
|
|
||||||
case DRUPAL_BOOTSTRAP_VARIABLES:
|
|
||||||
// Load variables from the database, but do not overwrite variables set in settings.php.
|
// Load variables from the database, but do not overwrite variables set in settings.php.
|
||||||
$conf = variable_initialize(isset($conf) ? $conf : array());
|
$conf = variable_initialize(isset($conf) ? $conf : array());
|
||||||
// Load bootstrap modules.
|
// Load bootstrap modules.
|
||||||
require_once DRUPAL_ROOT . '/includes/module.inc';
|
require_once DRUPAL_ROOT . '/includes/module.inc';
|
||||||
module_load_all(TRUE);
|
module_load_all(TRUE);
|
||||||
break;
|
}
|
||||||
|
|
||||||
case DRUPAL_BOOTSTRAP_SESSION:
|
/**
|
||||||
require_once DRUPAL_ROOT . '/' . variable_get('session_inc', 'includes/session.inc');
|
* Bootstrap page header: Invoke hook_boot(), intialize locking system, and send default HTTP headers.
|
||||||
drupal_session_initialize();
|
*/
|
||||||
break;
|
function _drupal_bootstrap_page_header() {
|
||||||
|
|
||||||
case DRUPAL_BOOTSTRAP_PAGE_HEADER:
|
|
||||||
bootstrap_invoke_all('boot');
|
bootstrap_invoke_all('boot');
|
||||||
if (!$cache && drupal_page_is_cacheable()) {
|
if (!drupal_page_get_cache(TRUE) && drupal_page_is_cacheable()) {
|
||||||
header('X-Drupal-Cache: MISS');
|
header('X-Drupal-Cache: MISS');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1567,17 +1612,17 @@ function _drupal_bootstrap($phase) {
|
||||||
ob_start();
|
ob_start();
|
||||||
drupal_page_header();
|
drupal_page_header();
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
case DRUPAL_BOOTSTRAP_LANGUAGE:
|
/**
|
||||||
drupal_language_initialize();
|
* Returns the current bootstrap phase for this Drupal process.
|
||||||
break;
|
*
|
||||||
|
* The current phase is the one most recently completed by drupal_bootstrap().
|
||||||
case DRUPAL_BOOTSTRAP_FULL:
|
*
|
||||||
require_once DRUPAL_ROOT . '/includes/common.inc';
|
* @see drupal_bootstrap()
|
||||||
_drupal_bootstrap_full();
|
*/
|
||||||
break;
|
function drupal_get_bootstrap_phase() {
|
||||||
}
|
return drupal_bootstrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue