0

I'm trying to bootstrap drupal from a standalone PHP script at the command line from sites/all/modules/mymodule/mymodule.php.

<?php
  chdir('/sandbox/mysite/');
  require_once './includes/bootstrap.inc'; 
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

I'm attempting to run it from the command line, but I get Drupal site-offline when I do (trimmed for brevity):

cd /sandbox/mysite
php sites/all/modules/mymodule/mymodule.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Site off-line | Pressflow</title>

The site is online and works fine from the browser. DRUPAL_BOOTSTRAP_DATABASE is where this fails, since I can bootstrap the DRUPAL_BOOTSTRAP_CONFIGURATION and DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE phases without a problem. Anyone run into this before? Thanks in advance.

  • What are you trying to do that requires a separate *.php script as opposed to a regular Drupal module? If you are looking to execute command line scripts against Drupal, then I would highly suggest you write your own Drush commands. – amateur barista Jul 5 '12 at 20:55
0

An easy way of writing CLI code for Drupal is implementing your own drush (http://drupal.org/project/drush) commands. Drush itself commes wirh handy example code.

  • It's a custom module/script that creates many nodes and will eventually run from its own crontab. I'm testing it locally currently and trying to bootstrap Drupal from it since it has some hardcoded paths that I can better write with access to Drupal globals. All info I've seen on bootstrapping Drupal from a CLI script etc. all use this technique and none mention running into Site Offline in the process. – Vincent Jul 5 '12 at 22:20
0

I was running this from MAMP and had to specify the direct path to PHP at the CLI for drupal to bootstrap correctly. It was calling Mac system php, not MAMP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.