Properly bootstrap drupal for standalone PHP file? This is what I have right now:

&lt;?php
    define('DRUPAL_ROOT', '/var/www/clients/client1/web15/web');
    include_once(DRUPAL_ROOT . '/includes/bootstrap.inc');
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//  drupal_flush_all_caches();  

    $users = views_get_view_result('userlist', 'uid_list');
    $i = 0;
    foreach ($users as $user) {
        $filename = 'sites/default/files/generated_pdfs/individual_pdf_report_' . $user-&gt;uid . '.pdf';
        generate_employee_pdf($user-&gt;uid, $filename);
        error_log('Generated ' . $filepath);
        $i++;
    }
    // create object
    $zip = new ZipArchive();
    // open archive
    if ($zip-&gt;open("sites/default/files/generated_zips/individual-reports.zip", ZIPARCHIVE::CREATE) !== TRUE) {
        die ("Could not open archive");
    }
    // initialize an iterator
    // pass it the directory to be processed
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("sites/default/files/generated_pdfs/"));
    // iterate over the directory
    // add each file found to the archive
    foreach ($iterator as $key=&gt;$value) {
        $zip-&gt;addFile(realpath($key), $value-&gt;getFilename()) or die ("ERROR: Could not add file: $key");
    }
    // close and save archive
    $zip-&gt;close();
?&gt;


I'm getting a bunch of errors from the above when run standalone. Works fine in my module. Some of the errors are:

Warning: Invalid argument supplied for foreach() in drupal_depth_first_search() (line 56 of /var/www/clients/client1/web15/web/includes/graph.inc).
Warning: Invalid argument supplied for foreach() in _module_build_dependencies() (line 229 of /var/www/clients/client1/web15/web/includes/module.inc).
Warning: include_once(sites/all/modules/views_bulk_operations/actions/archive.action.inc): failed to open stream: No such file or directory in views_bulk_operations_load_action_includes() (line 56 of /var/www/clients/client1/web15/web/sites/all/modules/views_bulk_operations/views_bulk_operations.module).
By far the easiest way to manage the bootstrap is to use drush php-script, alias scr.

file.php:

&lt;?php
echo l('Link', 'path');


Cli:

drush @alias scr file.php


Output:

&lt;a href="/path"&gt;Link&lt;/a&gt;


This way you need to deal with nothing with regard to the bootstrap, drush will solve it entirely for you, and gives you the ability to use it easily across sites thanks to aliases. (Might even work on remote sites, though I haven't tried that)