Re: How to call PHP as standalone from a CGI perl program?

From: Date: Sat, 08 Jul 2000 20:33:16 +0000
Subject: Re: How to call PHP as standalone from a CGI perl program?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-5559@lists.php.net to get a copy of this message
I figured it out. The problem is that php3 when called from a CGI perl program thinks that it's a CGI program itself, even though the intention is to run it standalone. That's why its behavior was different than when called from the command line. Clearing out the following environment variables in Perl before calling php3 solves the problem: delete $ENV{"SERVER_SOFTWARE"}; delete $ENV{'SERVER_NAME'}; delete $ENV{'GATEWAY_INTERFACE'}; delete $ENV{'REQUEST_METHOD'}; > ----- Original Message ----- > From: Steve Hsieh <steveh@eecs.umich.edu> > To: <php-general@lists.php.net> > Sent: Friday, July 07, 2000 8:32 PM > Subject: [PHP] How to call PHP as standalone from a CGI perl program? > > > Hi all, > > I am have some Perl-based CGI scripts that I'd like to use. However, I need > to call my existing PHP-based scripts to generate the header and footer of > each web page. I am having difficulties doing this - I'm hoping that someone > else out there can help tell me what is wrong with what I'm doing? Is there > some kind of 'security' issue involved? > > I have compiled a standalone version of php (ie: /usr/bin/php3) > with --enable-discard-path. > > Everything works as desired if I call my header function on the unix command > line. For example: > Suppose I have a file called 'header.php3' and it contains: "<? echo > "success.\n"; ?> > > % php3 header.php3 > X-Powered-By: PHP/3.0.16 > Content-type: text/html > > success. > % > > Works great when called on the command line. Now, I stick the call in a > Perl file in my cgi-bin directory called script.pl: > > #!/usr/bin/perl > open(FILE,"php3 -f header.php3 |"); > print "Content-type: text/html\n\n"; > while (<FILE>) > { > print; > } > close(FILE); > > > % perl script.pl > Content-type: text/html > > success. > % > > Everything still works exactly as expected when it's run from the command > line. But now when Apache runs this CGI script, PHP refuses to execute the > header.php3 file, but instead, prints out the perl file instead! > > ie: when I go to http://localhost/cgi-bin/script.pl > The output to my browser is literally: > > X-Powered-By: PHP/3.0.16 > Content-type: text/html > open(FILE,"php3 -f header.php3 |"); > print "Content-type: text/html\n\n"; > while (<FILE>) { print; } > close(FILE); > > >From the first line, it's clear that the perl CGI is running, and php has > been called. But it seems that for some reason, when the standalone php3 > binary is called from a CGI perl program, it refuses to process any input at > all, and instead, just prints out the contents of the perl script that > executed it. > > If anyone can explain to me what's going on, I'd really appreciate it. If > there's a better way to use PHP as a preprocessor whose output can then be > used by a CGI perl script, please tell me how. > > Thanks in advance... > Steve > > >

« previous php.general (#5559) next »