Re: calling php from perl
| From: | Matt McClanahan | Date: | Mon, 18 Dec 2000 21:36:42 +0000 |
| Subject: | Re: calling php from perl | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30933@lists.php.net to get a copy of this message | ||
On Mon, 18 Dec 2000, peter beardsley wrote:
> Hi,
> What I'm trying to accomplish is including the output of a php script in a
> perl CGI. The output of a perl/mod_perl CGI is not parsed by php, so I
> tried calling the php executable and printing the output, ala:
It probably won't help you much, but the situation you've described here
works fine for me, using an admittedly dated 4.0.1pl2 cgi binary.
> ## note: backticks in perl execute a command and returns stdout.
Yes, this is true in PHP as well.
> print
/usr/local/bin/php -f /home/httpd/cgi-bin/test.php;
>
> The contents of the test.php file is a simple:
>
> <?php print "hello world.\n" ?>
>
> What happens is PHP is smart enough to know that it's being called in a CGI
> context, and I get the following output in a browser:
When I run php -f invalidfilename, I don't get the X-Powered-By line.
> X-Powered-By: PHP/4.0.3pl1 Content-type: text/html No input file specified.
>
> If I run the perl script from the command line, it works fine. It's weird
> because I'm definitely specifying an input file with the "-f". I've tried
> many variations on this in perl including system(), various pipe and temp
> file hacks to no avail. I've poked around in the sources a bit and I think
> what's happening is that php is looking for a CGI parameter to specify an
> input file, and it's not there.
>
> Does anyone know how to work around this or an entirely different approach
> altogether?
Well, one option would be to put #!/usr/local/bin/php -q at the top of
your php script and chmod u+x it. Then from the perl side,
$output = /path/to/php/script.php;
Matt