1

I am attempting to run php scripts from a perl script on my goDaddy shared hosting. The PHP script I originally wrote exceeds their 120 sec time limit and the mySQL memory limit, so I am breaking the script up into several parts.

I want this to all run as one cron job, so I want to call a single perl script that runs 4-5 php scripts.

This is for my website, run with Drupal 7.

I've written a perl script with the following content:

my $command = '/web/cgi-bin/php5 -q $HOME/html/phpscript1.php';
exec ($command) or print STDERR "couldn't exec $command: $!";

Which calls a php scripts containing something like the following:

<?php

define('DRUPAL_ROOT', getcwd());

include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
....
do stuff
....
?>

But when I run this from perl (tried in both my $HOME directory and html directory) I see the following problems when I run the script (where XXXXXX is my godaddy account folder):

<b>Notice</b>:  Undefined index:  SCRIPT_NAME   
<b>/home/content/05/XXXXXXX/html/includes/bootstrap.inc</b> on line <b>1627</b><br />
<br />
<b>Notice</b>:  Undefined index:  REMOTE_ADDR in    
<b>/home/content/05/XXXXXXX/html/includes/bootstrap.inc</b> on line <b>2802</b><br />
<br />
<b>Notice</b>:  Undefined index:  argc in
<b>/home/content/05/XXXXXXX/html/includes/bootstrap.inc</b> on line <b>3290</b><br />

I've deduced that these are issues with FastGCI and that I probably need to define/export/point these index/variables to something, but I have been unable to find out what do to after extensive searching.

The PHP script copies images from an external server to my server using CURL

2 Answers 2

4

You're getting php notices because you're bootstrapping Drupal in your custom php script, and those variables are not defined on the cli.

That php script would probably be better implemented as a Drush command. Drush already sets up all the variables Drupal expects to be defined, and gives you a framework for easily running custom code in an instance of Drupal. Even if you didn't want to bother writing a custom command, you could just use drush's script command like so:

drush scr $HOME/html/phpscript1.php

Also, it's worth pointing out that those are just php notices. It's unlikely they are causing any issues with your script.

1
  • Thanks for your helpful comments. You are right about the code still running, but I was concerned about the errors. I tried to install drush, but I don't think I can without root access (silly goDaddy) Oct 18, 2012 at 5:35
0

So the answer here is don't bootstrap Drupal as you would when working in your drupal site (e.g. creating functions in a module). Rather, create a .php file that has the functions you need in it and use it outside of Drupal (e.g. above your html folder). Thanks to Mark for the quick help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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