Post processing Perl output through PHP

2001-07-16 Thread tau

Hi all,

I am having a knightmare trying to get some PHP into the output of
a Perl script. PHP. I've heard rumours of Apache 2.0 allowing multiple
filters, which would be perfect when it's out, but not yet obviously.

I've tried calling the CGI PHP from inside Perl in a few ways:

==
#!/usr/bin/perl
$result = `/usr/bin/php -q  EOF
?php echo Hello World; ?
EOF
`;
print Content-Type: text/html\n\n;
print PHP output was $result\n;
exit;
==

I've also tried running this command as a system() call in Perl, and
sending the output of /usr/bin/php to a temporary file, then using
Perl to open and read the contents of that file.

Both methods work if I call the script myself at a shell prompt. In
the case of the file creation, an 11 byte file is duly created.

However, when I call the perl script from a web browser, I lose the
PHP output. The code given above doesn't help narrow it down, but
in the case of the file creating version, I notice back at a shell
prompt that the call to /usr/bin/php has made a 0 byte file... which
obviously explains why I see nothing once Perl copies it to the output.

So, that means there is something about /usr/bin/php that is making it
generate absolutely no output when called via apache and the perl script.

I am guessing that this has to do with the environment variables, as I
can see no other way in which /usr/bin/php would be aware of a difference
in its environment.

So, my question is, does anybody know how to persuade PHP to give me the
output when called in this way... perhaps by forging an environment
variable from Perl first, or some clever command line switch...

Alternatively, and much preferred, some way of parsing the whole of the
perl output through PHP before returning to the browser. Then I could
just print PHP tags in my Perl output and Apache/mod_php would handle
the rest on the way back...

For reasons that really aren't worth going into, I need to access some
messy PHP functions from Perl, and I can't rewrite the PHP functions in
Perl because I have .php pages that need them, and I can't rewrite the
Perl scripts in PHP either. If I can't find a way of doing this, I will
probably tear all my hair out and then sit down to rewrite a separate
copy of every routine in Perl, and have two copies of all the code in
two different languages... knightmare come true !

Please please help me !!!

James
[EMAIL PROTECTED]



Re: Post processing Perl output through PHP

2001-07-16 Thread Ken Williams

[EMAIL PROTECTED]'s message:
 I'm not entirely sure if I'm getting what you're asking here - I get the
 impression you want the Perl program to call the php script, such as
 http://localhost/script.php3 and get the results from that script which you
 then push into  the results of your perl script, correct? The reason  I'm
 not sure is the part where you create a bunch of files in your tmp directory
 and then process those. Are you saying you're getting perl  to create PHP
 code, and getting Apache to process those, and then returning the results,
 or that you're getting perl to create a batch command essentially?

This is the problem.. I'm not just fetching a local php page, I am actually
using Perl to generate a bunch of PHP commands, which I then want Apache
to process on the way back to the client. Until a stable 2.0 Apache is
out and I can use SetOutputFilter, I am left with (what I think is the only
choice left...) creating a temporary file, under DOCUMENT_ROOT, putting the
generated PHP into it, using LWP or friends to fetch that page throuh Apache,
which will then parse the PHP with mod_php, and send that output back to
the client via 'print $fetched_contents;'

You'll be happier, and the code will run faster, if you use an Apache
subrequest instead of a full-blown LWP request.  If you're not
familiar with subrequests, look up $r-lookup_uri() and
$r-lookup_file() in the mod_perl docs and/or the Eagle book.


-Ken Williams
 The Math Forum
 [EMAIL PROTECTED]



Re: Post processing Perl output through PHP

2001-07-15 Thread darren chamberlain

[EMAIL PROTECTED] [EMAIL PROTECTED] said something to this effect on 07/14/2001:
 I am having a nightmare trying to get some PHP into the output of
 a Perl script. PHP. I've heard rumours of Apache 2.0 allowing multiple
 filters, which would be perfect when it's out, but not yet obviously.

Add PHP support to your server, and use subrequests to get the
results of the processing.  Or, run PHP on another server, and
use LWP to fetch pages from that server which will be included
the output fromt he main server.

(darren)

-- 
I respect faith, but doubt is what gives you an education.
-- Wilson Mizner



Re: Post processing Perl output through PHP

2001-07-15 Thread perl

  I am having a nightmare trying to get some PHP into the output of
  a Perl script. PHP. I've heard rumours of Apache 2.0 allowing multiple
  filters, which would be perfect when it's out, but not yet obviously.

 Add PHP support to your server, and use subrequests to get the
 results of the processing.  Or, run PHP on another server, and
 use LWP to fetch pages from that server which will be included
 the output fromt he main server.

Running PHP elsewhere is out of the question, as both the PHP and Perl
code uses data stored on the system. By 'Add PHP support', if you mean
adding PHP such that I can write and serve .php documents, then this
is already in place, as most of the site is in PHP!, but if you mean
something other than this... please explain more ?

'and use subrequests to get the results'

Sorry for sounding stupid, but what exactly do you mean... ? I am
calling the PHP CGI binary from inside Perl to get output, and it works
fine from a shell, but not through Apache. Do you mean using lynx to
fetch a page on the server to a file and use that.. ?

That is the only solution I have found to date, calling lynx -dump with
a http://localhost/ address to get Apache to return the PHP file to me,
with all the correct PHP expansion. I can then read this output using the
perl script and include it in my perl output, back to the browser.

The problem comes in that I want to specify a host of different PHP
commands in my Perl output, and get Apache to process them on the way
back, so using this trick, I have to create (from the perl script) a bunch
of temporary files containing PHP, somewhere (now globally writable) under
the DOCUMENT_ROOT tree, fetch them using lynx again needing to use a writable
area (although /tmp is fine here), and then include them in my output, and
then clean up the files!

There must be an easier way !!!

Please help me... I've spent over 20 hours reading nearly every forum
on phpbuilder.net and a whole host of other sites now, and I've found
two others who have exactly the same problem as me, and having emailed them,
they never found an elegant solution... they ended up re-writing all their
code in one or the other.

But I've got over 40,000 lines of Perl, and the entire rest of the site is
in PHP, so this is an unbelievable task if I have to resort to it !?!?!?

Help ???

J.






Re: Post processing Perl output through PHP

2001-07-15 Thread Sean Chittenden

 There must be an easier way !!!

Sorry.  :~)  You could hack mod_proxy or mod_backhand and put
PHP on a different server (or same server on different port).  If you 
have to pick between the two, I recommend backhand (comes with a lot of 
other really nice features).

http://www.backhand.org/

-sc

 Please help me... I've spent over 20 hours reading nearly every forum
 on phpbuilder.net and a whole host of other sites now, and I've found
 two others who have exactly the same problem as me, and having emailed them,
 they never found an elegant solution... they ended up re-writing all their
 code in one or the other.

Yup, sorry.  Apache 2.0 has filter support so this may be an 
easier solution in the future.  I'm writing ruby-tmpl (mod_ruby module) 
that has output processing because this isn't an easy problem to solve.

 But I've got over 40,000 lines of Perl, and the entire rest of the site is
 in PHP, so this is an unbelievable task if I have to resort to it !?!?!?

Bummer  if this is for a company, you may want to look into
an outside contracting firm to help you with this.  ;~)  
http://www.mha.ca/ - These guys are great PHP contractors that I've used
before.

-sc 

-- 
Sean Chittenden

 PGP signature


RE: Post processing Perl output through PHP

2001-07-15 Thread perl

 I'm not entirely sure if I'm getting what you're asking here - I get the
 impression you want the Perl program to call the php script, such as
 http://localhost/script.php3 and get the results from that script which you
 then push into  the results of your perl script, correct? The reason  I'm
 not sure is the part where you create a bunch of files in your tmp directory
 and then process those. Are you saying you're getting perl  to create PHP
 code, and getting Apache to process those, and then returning the results,
 or that you're getting perl to create a batch command essentially?

This is the problem.. I'm not just fetching a local php page, I am actually
using Perl to generate a bunch of PHP commands, which I then want Apache
to process on the way back to the client. Until a stable 2.0 Apache is
out and I can use SetOutputFilter, I am left with (what I think is the only
choice left...) creating a temporary file, under DOCUMENT_ROOT, putting the
generated PHP into it, using LWP or friends to fetch that page throuh Apache,
which will then parse the PHP with mod_php, and send that output back to
the client via 'print $fetched_contents;'

 Either way, the 'simple' way to do this is using LWP, as suggested by
 someone else on the list. Even if it's running on the same server, LWP will
 work just fine. LWP is a perl module that you can get on CPAN to do http
 requests for you. That is, directly in your perl program instead of using
 lynx, you can call to get another web page like so (untested):

Ironically, having tried the suggestion from Darren, I discover that I don't have
LWP installed. My sysadmin however, will install anything for me as long as
I provide him with an RPM for it.

I don't mean to sound lazy, and I have just checked rpmfind.net, but I can't
quickly put my hands on an rpm which includes LWP::Simple for Red Hat 7.0

Assuming I sort this out, I think I will have found a way out, by creating a file
with my PHP in, as described above.

On another note, Apache.org mentions the 'forthcoming' stable release of 2.0.
Does anybody have any idea of how long this will be... From what I read on the
net, and the Apache FAQ, it will be very simple to specify that a certain
directory will be filtered through another module, ie getting perl script output
filtered through PHP by Apache before returning to the client. Perhaps somebody
has experience with the beta release of Apache 2.0 ???

James.






Re: Post processing Perl output through PHP

2001-07-15 Thread raptor


 Ironically, having tried the suggestion from Darren, I discover that I
don't have
 LWP installed. My sysadmin however, will install anything for me as long
as
 I provide him with an RPM for it.

 I don't mean to sound lazy, and I have just checked rpmfind.net, but I
can't
 quickly put my hands on an rpm which includes LWP::Simple for Red Hat 7.0

]- get checkinstall and install LWP on your computer as stated in the
checkinstall docs and it will make the RPM for U :)
http://mayams.net/~izto/checkinstall-en.html
after u install checkinstall u have to do something like this :

perl Makefile.pl
make
make test
checkinstall make install

HtH
=
iVAN
[EMAIL PROTECTED]
=






Re: Post processing Perl output through PHP

2001-07-15 Thread Tom Brown


better, someone has written a makerpm.pl script which will build a .spec
file for an RPM, from which you can build .src.rpm or .i386.rpm files...
there is a version out there that works with rpm4, I won't post the it
here in the hopes that someone who is maintaining a version _will_ speak
up... basically it comes down to:

/usr/src/redhat/SOURCES ./makerpm.pl --spec --source tarball.1.1.tgz
/usr/src/redhat/SOURCES cd ../SPECS
/usr/src/redhat/SPECS rpm -ba tarball-1.1.spec
/usr/src/redhat/SPECS rpm -i ../RPMS/i386/perl-tarball-1.1.rpm

I've typed the above from memory and may have botched filenames/syntaxes
etc... search the list for similar and probably better examples..

On Sun, 15 Jul 2001, raptor wrote:

 
  Ironically, having tried the suggestion from Darren, I discover that I
 don't have
  LWP installed. My sysadmin however, will install anything for me as long
 as
  I provide him with an RPM for it.
 
  I don't mean to sound lazy, and I have just checked rpmfind.net, but I
 can't
  quickly put my hands on an rpm which includes LWP::Simple for Red Hat 7.0
 
 ]- get checkinstall and install LWP on your computer as stated in the
 checkinstall docs and it will make the RPM for U :)
 http://mayams.net/~izto/checkinstall-en.html
 after u install checkinstall u have to do something like this :
 
 perl Makefile.pl
 make
 make test
 checkinstall make install
 
 HtH
 =
 iVAN
 [EMAIL PROTECTED]
 =
 
 
 

--
[EMAIL PROTECTED]   | Always bear in mind that your own resolution to
http://BareMetal.com/  | success is more important than any other one
web hosting since '95  | thing. - Abraham Lincoln




Re: Post processing Perl output through PHP

2001-07-15 Thread barries

On Sun, Jul 15, 2001 at 10:49:30AM -0400, darren chamberlain wrote:
 [EMAIL PROTECTED] [EMAIL PROTECTED] said something to this effect on 07/14/2001:
  I am having a nightmare trying to get some PHP into the output of
  a Perl script. PHP. I've heard rumours of Apache 2.0 allowing multiple
  filters, which would be perfect when it's out, but not yet obviously.
 
 Add PHP support to your server, and use subrequests to get the
 results of the processing.

How would you keep the subrequest from writing to the socket and,
instead, to a buffer? Apache 2.0 has that that sort of possibility:
implement a Perl output filter and configure it in front of a PHP
content handler. I think you'd have to hack Apache 1.x to do this, kinda
like the SSL modules have to.

- Barrie



Post processing Perl output through PHP

2001-07-14 Thread perl

Hi all,

I am having a nightmare trying to get some PHP into the output of
a Perl script. PHP. I've heard rumours of Apache 2.0 allowing multiple
filters, which would be perfect when it's out, but not yet obviously.

I've tried calling the CGI PHP from inside Perl in a few ways:

==
#!/usr/bin/perl
$result = `/usr/bin/php -q  EOF
?php echo Hello World; ?
EOF
`;
print Content-Type: text/html\n\n;
print PHP output was $result\n;exit;
==

I've also tried running this command as a system() call in Perl, and
sending the output of /usr/bin/php to a temporary file, then using
Perl to open and read the contents of that file.

Both methods work if I call the script myself at a shell prompt. In
the case of the file creation, an 11 byte file is duly created.

However, when I call the perl script from a web browser, I lose the
PHP output. The code given above doesn't help narrow it down, but
in the case of the file creating version, I notice back at a shell
prompt that the call to /usr/bin/php has made a 0 byte file... which
obviously explains why I see nothing once Perl copies it to the output.

So, that means there is something about /usr/bin/php that is making it
generate absolutely no output when called via apache and the perl script.
I am guessing that this has to do with the environment variables, as I
can see no other way in which /usr/bin/php would be aware of a difference
in its environment.

So, my question is, does anybody know how to persuade PHP to give me the
output when called in this way... perhaps by forging an environment
variable from Perl first, or some clever command line switch...

Alternatively, and much preferred, some way of parsing the whole of the
perl output through PHP before returning to the browser. Then I could
just print PHP tags in my Perl output and Apache/mod_php would handle
the rest on the way back...

For reasons that really aren't worth going into, I need to access some
messy PHP functions from Perl, and I can't rewrite the PHP functions in
Perl because I have .php pages that need them, and I can't rewrite the
Perl scripts in PHP either. If I can't find a way of doing this, I will
probably tear all my hair out and then sit down to rewrite a separate
copy of every routine in Perl, and have two copies of all the code in
two different languages... nightmare come true !

Please please help me !!!

James
[EMAIL PROTECTED]