Calling PHP cgi from Perl

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
ozbcoz
Forum Newbie
Posts: 4
Joined: Tue Oct 08, 2002 8:21 pm

Calling PHP cgi from Perl

Post by ozbcoz »

Hi,
want to call a PHP prog (written as a cgi and using the shebang etc) from perl.
used:
$a=`/usr/local/php/bin/php /home/useridz/http/testphp.php -q fred=testing`;

but cant get the vars to get across to the PHP mod. The PHP cgi works fine otherwise - returns info it but doesnt see the input variables.
globals is on but $argv is empty and $argc is 0

any ideas anyone ?

cheers

Jim
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

make -q the first argument to the php executable. as it is now "-q" is being passed to the script and not the interpreter
ozbcoz
Forum Newbie
Posts: 4
Joined: Tue Oct 08, 2002 8:21 pm

Post by ozbcoz »

yep - tried it with and without the -q - get the same results - eg:

$a=`/usr/local/php/bin/php /home/ozbcoz/http/testphp.php fred=testing`;
print "$a";

with the php script showing:

#!/usr/local/php/bin/php -q
<?
$v=$HTTP_POST_VARS;
$g= $HTTP_GET_VARS;
$p= $HTTP_POST_FILES;
print "<br>POST_VARS = ";
var_dump($v);
print "<br>GET_VARS = ";
var_dump($g);
print "<br>POST_FILES = ";
var_dump($p);
print "count=$argc<br>";
print "0=$argv[0]<br>";
print "1=$argv[1]<br>";
print "2=$argv[2]<br>";
phpinfo();
?>

the outout comes out as:

POST_VARS = array(0) { }
GET_VARS = array(0) { }
POST_FILES = array(0) { } count=0
0=
1=
2=
plus the phpinfo bumpf

cheers

Jim
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

i don't think you need the shebang in you php file
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

If you have a sha-bang in the script and the script is executable you can invoke the script directly, ie in perl
$a = `/home/ozbcoz/http/testphp.php fred=testing`;

I don't know what, if any parsing it will do with the fred=testing, I suspect that it argv[1] will equal "fred=testing" as command-line arguements are space delimited.

I have a script that I use in cron as /usr/local/bin/compinabox/rebuild_stats.php arguement

the script starts

Code: Select all

#!/usr/local/bin/php
&lt;?php
if ($argv&#1111;1]=="") die ("Usage: foo....");
?&gt;
Does this help at all?
ozbcoz
Forum Newbie
Posts: 4
Joined: Tue Oct 08, 2002 8:21 pm

Post by ozbcoz »

works for me if I do it from the command line but not when called from a Perl cgi - frustrating :(
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

In the perl cgi are your cleaning the PATH variables and ENV? I know that taint mode won't like you run extranal programs unless you've done this......
ozbcoz
Forum Newbie
Posts: 4
Joined: Tue Oct 08, 2002 8:21 pm

Post by ozbcoz »

hi - thanks for perservering with me on this :-)

I'm not running in taint mode (but if I were how would I clear those vars ( $ENV = ""; ?)
Post Reply