using drupal 7 functions in external files
Make a copy of the index.php file and rename it to foo.php. index.php ships by default with Drupal 7 and can be found in the root of the Drupal source.

Remove the last call to menu_execute_active_handler() from the new file. This is the router that calls an appropriate page handler based on the query string. You wouldn't need this.

This leaves:

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
/* Stub */


As you can see, Drupal is now bootstrapped fully. This makes the API methods of Drupal core and all other enabled core and contributed modules available for use in this script from the fourth line.