How to call PHP as standalone from a CGI perl program?
| From: | Steve Hsieh | Date: | Sat, 08 Jul 2000 01:32:07 +0000 |
| Subject: | How to call PHP as standalone from a CGI perl program? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-5501@lists.php.net to get a copy of this message | ||
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