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:
// Assuming the script is located in Drupal Root directory.
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');