As a developer we always been into position where we need to write a custom script which bootstrap's Drupal Core from code and do some operations. This is pretty straight forward when working single site. But when working with Multisite or sub-site, how we can do this.

So for example, we've 2 multi-site built using one Drupal Code base, respectively and and we've a custom PHP script which does some data processing for site. To achieve this we can write a small code snippet as below:

// Assuming the script is located in Drupal Root directory.
define('DRUPAL_ROOT', getcwd());
DRUPAL_ROOT . '/includes/';

// Tell Drupal about which site we want to bootstrap,
// using drupal_override_server_variables() function.
$variables = array('url' => 'http://');