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 http://example.com and http://a.example.com and we've a custom PHP script which does some data processing for http://a.example.com site. To achieve this we can write a small code snippet as below:
<?php
// Assuming the script is located in Drupal Root directory.
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

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

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
?>

Reference:

Tags
Submitted by ychaugule on