You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John ORourke <jo...@o-rourke.org> on 2005/03/13 15:20:27 UTC

[ap2/mp2] post-processing handler output with another module (php)

Hi,

I'm sure I should know this, but I'm trying to post-process the output of my
handler with PHP.  I'm still a bit green on Apache inner workings and just
can't make it happen.

I've made sure the php LoadModule statement is before the Perl one in
httpd.conf.  I've tried using a URI which ends in .php, I've tried setting
the content_type to application/x-httpd-php, it doesn't work.

I haven't tried returning DECLINED, and I haven't tried it with a URI that
maps to a real file.  I'll try those today if I can.

Anyone know if it's possible or easy or both?

cheers
John


Re: [ap2/mp2] post-processing handler output with another module (php)

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Matthew Westcott wrote:
> On 13 Mar 2005, at 14:20, John ORourke wrote:
> 
>> Hi,
>>
>> I'm sure I should know this, but I'm trying to post-process the output
>> of my
>> handler with PHP.  I'm still a bit green on Apache inner workings and
>> just
>> can't make it happen.
> 
> 
> Just to be clear - your mod_perl handler is outputting PHP source which
> you then hope to feed to PHP? If so, I don't think it's possible
> directly - PHP can only be invoked as a response handler which reads the
> script from the filesystem, and there can only be one response handler
> in use.

if you're using apache 2.0 and recent versions of php (I'm looking at 5.0.3)
it seems as though php can be invoked as an output filter as well.  so, just
from grepping sapi_apache2.c it looks like something akin to

  <Location /foo>
    SetHandler modperl
    PerlResponseHandler My::Foo
    SetOutputFilter PHP
  </Location>

should do the trick, provided your mod_perl handler sets the content-type to
'application/x-httpd-php'.

HTH

--Geoff

RE: [ap2/mp2] post-processing handler output with another module (php)

Posted by John ORourke <jo...@o-rourke.org>.
-----
From: Matthew Westcott [mailto:matthew.westcott@torchbox.com]
Sent: 13 March 2005 15:27

On 13 Mar 2005, at 14:20, John ORourke wrote:

> > I'm sure I should know this, but I'm trying to post-process the output
> > of my
> > handler with PHP.  I'm still a bit green on Apache inner workings and
> > just
> > can't make it happen.

> Just to be clear - your mod_perl handler is outputting PHP source which
> you then hope to feed to PHP? If so, I don't think it's possible
> directly - PHP can only be invoked as a response handler which reads
> the script from the filesystem, and there can only be one response
> handler in use. That said, I have two suggestions of varying hairiness:

Yes, I'm writing out php source - the single response handler kind of kills
my idea!

I'll pipe the output through command-line php, it's only for the occasional
bit of code.

thanks
John



Re: [ap2/mp2] post-processing handler output with another module (php)

Posted by Matthew Westcott <ma...@torchbox.com>.
On 13 Mar 2005, at 14:20, John ORourke wrote:

> Hi,
>
> I'm sure I should know this, but I'm trying to post-process the output 
> of my
> handler with PHP.  I'm still a bit green on Apache inner workings and 
> just
> can't make it happen.

Just to be clear - your mod_perl handler is outputting PHP source which 
you then hope to feed to PHP? If so, I don't think it's possible 
directly - PHP can only be invoked as a response handler which reads 
the script from the filesystem, and there can only be one response 
handler in use. That said, I have two suggestions of varying hairiness:

1. Make your mod_perl handler a PerlFixupHandler (or any appropriate 
earlier stage) which writes the PHP script to a file, and then set up 
PHP as the response handler:
$r->handler('php-script');
You may need to tinker with other response fields to avoid PHP getting 
confused, such as re-statting the file:
my $finfo = APR::Finfo::stat($filename, APR::FINFO_NORM, $r->pool());
$r->finfo($finfo);

2. Forget about using the PHP Apache module; pipe the output of your 
PerlResponseHandler through the command-line PHP interpreter instead.

- Matthew