Bootstrapping Drupal from the command line Here is what I'm trying to do : 


Write a php script that import external data into drupal.
Run that script every night with a cron that executes it using php, not wget.


In other words, I need my import script to run from the command line.

First step is done and working great when run as a module from Drupal. So I took all required bits of it, created a new file, and bootstraped drupal. After fixing a few warnings and errors (path issues mainly), the file is executed but actually no job is done. 

So I start adding echo commands to see where everything goes to hell. And it appears that it's right after

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);


What I mean is that no error, warning or whatever is raised, but it's like the script exit somewhere inside that call. 

I tried to lower the boostrap level to DRUPAL_BOOTSTRAP_LANGUAGE, but then I get the following error : 


  Fatal error: Call to undefined function field_info_field() in /www/includes/entity.inc on line 768


I'm a bit lost on what happens and would welcome any suggestion.

Also, here is the beginning of the script that bootstrap Drupal : 

&lt;?php
    ini_set("display_errors", 1);
    error_reporting(E_ALL);
    chdir('/www/');

    $cmd = 'index.php';
    $_SERVER['HTTP_HOST']       = 'default';
    $_SERVER['PHP_SELF']        = '/index.php';
    $_SERVER['REMOTE_ADDR']     = '127.0.0.1';
    $_SERVER['SERVER_SOFTWARE'] = NULL;
    $_SERVER['REQUEST_METHOD']  = 'GET';
    $_SERVER['QUERY_STRING']    = '';
    $_SERVER['PHP_SELF']        = $_SERVER['REQUEST_URI'] = '/';
    $_SERVER['HTTP_USER_AGENT'] = 'console';    

    define('DRUPAL_ROOT', '/www/');
    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);

    // nothing gets executed past this point
    print("0\n");
Don't even try this. Use drush, it is meant for this type of things precisely.

The drush php-script command will allow you to run any PHP script in the context of Drupal, but I would recommend writing those as a proper command inside a custom module.