Drupal calls the function _drupal_bootstrap_configuration().
Error Handling
The very first thing that happens in the first phase of thebootstrap process is Drupal defines its own error handlingfunctions. Up until this point if an error had occurred in the codephp would have used its own error handling to report the problem.Luckily very few lines of code have been executed to thispoint.
Drupal sets an error handler as well as an exception handler.The exception handler is new to Drupal since Drupal 7 now includesobject oriented code which when called could generateexceptions.
What happens inside of these error handling functions is bestleft to its own discussion. Just be aware that they exist and theyare defined very early on. Also note the error handling code foundin the error.inc file isn't loaded until the first error occurs.Our first encounter of lazy loading inDrupal 7.
drupal_environment_initialize().
<?php
function drupal_environment_initialize() {?>
In this function Drupal first cleans up parts of the$_SERVER super global. It makessure that there is a valid server protocol variable set. It alsodoes a security check on the http host variable.
<?php
// Whenclean URLs are enabled, emulate ?q=foo/bar using REQUEST_URI. Itis
// not possible to append the query string usingmod_rewrite without the B
// flag (this was added in Apache 2.2.8),because mod_rewrite s the
// path before passing it on to PHP. This is aproblem when the path contains
// e.g. "&" or "%" that havespecial meanings in URLs and must be encoded.
$_GET['q'] =request_path();
?>
The request_path() functioncleans up the default $_GET['q']value as per the code comments above.1
The rest of drupal_environment_inistialize is literallyself explanatory.
<?php
// EnforceE_ALL, but allow users to set levels not part of E_ALL.
error_reporting(E_ALL| error_reporting());
?>
With drupal_environment_initialize() complete jumpback to _drupal_bootstrap_configuration().
Its at this stage that Drupal, completely out of the blue,decides to start a timer function (to keep tack of page executiontime). This is rather unexpected since you might not have knownthat Drupal has timer functions at all - let alone ones that arecalled on every single page load. Just something to keep in mindwhen developing your next killer module - you have access totimer_start,timer_read, and timer_stop functions.
drupal_settings_initialize();
Finally _drupal_bootstrap_configuration callsdrupal_settings_initialize().
<?php
function drupal_settings_initialize() {
global $base_url, $base_path, $base_root;
?>
It starts off by defining a long list of global variables thatget used throughout Drupal.
Drupal then looks for and includes the settings.php file. Thisfile is often found in /sites/default/settings.php, but if you havea multi-site install of Drupal it could be in different directoriesunder /sites/ depending on which site you are currently looking at.Drupal figures out which directory settings.php is in with a callto conf_path().
I won't go through conf_path() line by line, butit is worth reading the documentation for that function if you everwondered how Drupal just knew where to load settings from2.
An entire post could be dedicated to settings.php, but what youneed to know here is that your site's configuration is loaded inthe first bootstrap phase. It is very much worthwhile to read thecode comments in settings.php.
In the rest of the function, variables for base URL, cookiedomain, and session name are all set correctly.
And with that, the first phase bootstrap phase is complete.
Summary
The first bootstrap phase is all about laying the foundation forthe rest of page execution. Custom error handling code is prepared,php settings are modified, settings.php gets loaded and some keyvariables used later on are initialized.
Next time I'll look at phase 2 of the Drupal bootstrapprocess.
Footnotes
Whenyou have clean urls enabled, you are hiding 'ugly' urls from yoursite's visitors. The ugly url is in the form http://example.com/index.php?q=foo/bar/baz.Its easy to forget that Drupal paths are really a single parameterpassed via HTTP GET.