Page request by drupal 7
2014 01 May

How a page request is processed by Drupal 7 ?

You entered an URL and suddenly Drupal returns a page, how does Drupal do it ? 

Having a conceptual framework of what happens when a request is received by Drupal is helpful, so this blog provides a quick walk-through. If you want to trace it yourself, use a good debugger, and start at index.php, which is where Drupal receives most of its requests. The sequence outlined in this section may seem complex for displaying a simple web page, but it is rife with flexibility.

Let's consider an URL for reference : https://www.innoraft.com/blogs/how-page-request-processed-drupal-7

You have requested this page, now this request is recieved by webserver (nginx or apache or etc) from browser, now an intresting question how this request is reaches Drupal. Let's have a look :

1. Apache Web Server :

  1. Apache web server respects Drupal’s .htaccess file, so some PHP settings are initialized, and the URL is examined.
  2. The mod_rewrite rule in Drupal’s .htaccess file looks at the incoming URL and separates the base URL from the path. So now path for our URL is blog/how-page-request-served-drupal-7
  3. This path is assigned to a query parameter q=blog/how-page-request-served-drupal-7
  4. Now the resulting url becomes https://www.innoraft.com/blogs/how-page-request-processed-drupal-7

2. Nginx :

  1. Nginx basically search for virtual host's config file and then after processing the request send this to Drupal. Following is the primary block for request processing :
# This is our primary location block.

location / {

index index.php;

try_files $uri $uri/ @rewrite;

expires max;

}

location @rewrite {

rewrite ^/(.*)$ /index.php?q=$1;

}

     2. What this block of code does, it redirects the incoming request to drupal's index.php in the same fashion as what apache does.

So now our page URL is changed from https://www.innoraft.com/blogs/how-page-request-processed-drupal-7 => http://www.innoraft.com/index.php?q=blogs/how-page-request-processed-drupal-7

Almost all the page request coming to drupal are processed in index.php except some request like public file downloads etc. Till now Drupal has not started processing the request.

How Drupal will process the page request ?

Let's have a look on the code of index.php file :

define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();

Yes, Four (4) lines of code returns every single page on your drupal website ! That's pretty amazing. so whats going on here.

A call is made to getcwd() and output is assigned to the 'DRUPAL_ROOT' constant, basically with this drupal is telling itself where it is installed.

Using this constant Drupal loads the bootstrap.inc file required for starting all the mechanism in Drupal. The code of this file is run on each and every page request.

After loading bootstrap.inc file, drupal_bootstrap() function is called with the value of the DRUPAL_BOOTSTRAP_FULL constant passed. In short this function starts all the mechanism like session, basic configuration, database, page caching, menu, ajax etc. After starting all of the mechanisms it executes the menu_execute_active_handler() for routing it to appropriate callback function. Basically this function looks at the query parameter (blog/how-page-request-served-drupal-7) and then look for the appropriate callbacks.

So till now we have all the content related to the requested URL, now Theming layer comes into action and theme the content.

Theming involves transforming the data that has been retrieved, manipulated, or created into HTML (or XML or other output format). Drupal will use the theme which is selected by the administrator to give the web page the correct look and feel. The resulting output is then sent to the web browser (or other HTTP client).

And that is how your page request is processed....!!!!

Latest Blogs

webshop

Drupal: The ideal solution for your e-Commerce Website

In the last few decades, the online merchandising sector has made strides at an unprecedented pace following that, the demand and emergence of many e-commerce platforms are on the rise. 

Read More

Drupal 9 Upgrade

The Roadmap to upgrade Drupal site to Drupal 9

Drupal is approaching with its next big evolution and the upcoming release that is none other than Drupal 9.

Read More

How to Choose Web Development Agencies

Points to check before choosing the right website development company

In today’s day and age, where the digital population is increasing exponentially, no credible business can or should refrain from having a strong and steady web presence.

Read More

Wordpress to Drupal

Should I plan to move my Wordpress Website into the Latest Drupal version?

If you're here, I assume you already have a website built on WordPress but you're not satisfied with it, or perhaps you're here to have a clear idea about why you should give a thought to migrating

Read More