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

From: Date: Sat, 08 Jul 2000 22:59:56 +0000
Subject: Re: How to call PHP as standalone from a CGI perl program?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-5525@lists.php.net to get a copy of this message
I had this problem a while back, I actually had to write a C wrapper to call php I think it stems from perl reading from STDIN (parser) as well as php reading from stdin... since they're reading from the same fd stuff gets messed up. correct me if I'm wrong.. anyone.. for I'm kinda curious if there's a good workaround here.. Ryan ----- 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 (#5525) next »