Having read the PHP Builder articles:
http://www.phpbuilder.com/columns/jayesh20021111.php3
http://www.phpbuilder.com/columns/darrell20000319.php3
And a large amount of other material, manuals etc. I'm still having problems executing a php script from a Perl CGI. I've even read articles regarding executing a Perl script from PHP but have found next to nothing regarding the opposite case.
I can run a command from the shell that executes the PHP shell script flawlessly. The trouble comes when I try to use the Perl CGI via the system() or exec() commands to run the PHP shell script. I have tried a number of options and combinations. Currently the Perl CGI executes properly and nothing is returned via the error log. I've set all permissions as necessary and the only thing that is a mystery is to why the counter.txt file isn't updating when the Perl CGI is run (which in turns calls the counter.php shell script). Currently the headers from counter.php are echoed in the output from the Perl CGI so I'm pretty sure it's running, but the file counter.txt is not affected. (I've tried chmod 666 the counter.txt file but no change.)
I'm wondering if there isn't some sort of PHP configuration issues that require turning on either CGI or CLI options. I have PHP 4.2.3
with both apache_mod and CGI/PHP binary versions enabled.
THE PERL CGI CODE
(with file path after 'system "php /' altered):
#!/usr/bin/perl -w
print <<BEGINTEST;
this test rocks your body body begin.
BEGINTEST
system "php /physical/server/path/vps/path/counter.php" || die "cannot do it, error = $!\n";
print <<ENDTEST;
this test rocks your body body end.
ENDTEST
THE PHP SHELL SCRIPT CODE:
#!/usr/local/bin/php -q
<?php
$NUMBER;
# retrieve counter if file exists
if(file_exists("counter.txt"))
{
$FILE = fopen("counter.txt","r");
if($NUMBER = fgets($FILE,999))
{ $NUMBER = trim($NUMBER); }
fclose($FILE);
}
# save incremented counter to file
# Make certain that PHP has access
# rights to counter.txt file.
# The access rights on unix can be changed
# by typing: chmod a+w counter.txt
$FILE = fopen("counter.txt","w");
fwrite($FILE,$NUMBER + 1);
fclose($FILE);
?>
Any suggestions on enabling the execution of this PHP shell script from a call from a Perl CGI? The reason I'm after this particular method is my hosting does not seem to allow PHP execution from the cgi-bin and I need to access a proprietary shopping cart Order API via a custom script that must reside in the cgi-bin. I want to adjust the current PHP session by adding information from the Order API.
I want to start by getting PHP shell scripts to execute through the Perl CGI (though command line seems to allow them to operate fine.) Any ideas?