Solar Nick Solar Nick - 1 year ago 148
PHP Question

Running PHP from Perl Script

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:


define('DRUPAL_ROOT', getcwd());

include_once DRUPAL_ROOT . '/includes/';
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/</b> on line <b>1627</b><br />
<br />
<b>Notice</b>: Undefined index: REMOTE_ADDR in
<b>/home/content/05/XXXXXXX/html/includes/</b> on line <b>2802</b><br />
<br />
<b>Notice</b>: Undefined index: argc in
<b>/home/content/05/XXXXXXX/html/includes/</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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download