You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Brian Mearns <bm...@ieee.org> on 2009/03/14 06:09:19 UTC

[users@httpd] PHP script as Apache filter or "callback"

I've got a PHP script that I want to call for every request under a
certain location. Specifically, I want to alter/set the response
headers using this script. I know headers can be set in other ways,
but in this case, the heders are set using some fairly complex logic
which I don't think can be done in the conf file directly, plus the
PHP script will have some other side effects on the server.

Does anyone know of a way to do this? If not, can anyone point me to a
good tutorial for writing apache filters?

Thanks!
-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.edu/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] PHP script as Apache filter or "callback"

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Eric Covener wrote:
> 
> AFAICT it seems like php-as-a-filter is somewhat out of fashion, and
> might require a rebuild of your PHP mod (if even still supported).

It was never apache2handler; it's a different sapi named apache2filter.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] PHP script as Apache filter or "callback"

Posted by Eric Covener <co...@gmail.com>.
On Sat, Mar 14, 2009 at 9:53 AM, Brian Mearns <me...@gmail.com> wrote:
> On Sat, Mar 14, 2009 at 7:59 AM, André Warnier <aw...@ice-sa.com> wrote:
>> Brian Mearns wrote:
>>>
>>> I've got a PHP script that I want to call for every request under a
>>> certain location. Specifically, I want to alter/set the response
>>> headers using this script. I know headers can be set in other ways,
>>> but in this case, the heders are set using some fairly complex logic
>>> which I don't think can be done in the conf file directly, plus the
>>> PHP script will have some other side effects on the server.
>>>
>> Maybe you'd have more chances here ? http://www.php.net/support.php
>
> I don't think this is really a PHP issue; I already have the script
> working, I just need to know how to apache to invoke it.

AFAICT it seems like php-as-a-filter is somewhat out of fashion, and
might require a rebuild of your PHP mod (if even still supported).

If you don't need high performance, mod_ext_filter might be a good stop-gap.

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] PHP script as Apache filter or "callback"

Posted by Brian Mearns <me...@gmail.com>.
On Sat, Mar 14, 2009 at 7:59 AM, André Warnier <aw...@ice-sa.com> wrote:
> Brian Mearns wrote:
>>
>> I've got a PHP script that I want to call for every request under a
>> certain location. Specifically, I want to alter/set the response
>> headers using this script. I know headers can be set in other ways,
>> but in this case, the heders are set using some fairly complex logic
>> which I don't think can be done in the conf file directly, plus the
>> PHP script will have some other side effects on the server.
>>
> Maybe you'd have more chances here ? http://www.php.net/support.php

I don't think this is really a PHP issue; I already have the script
working, I just need to know how to apache to invoke it.

>
>> Does anyone know of a way to do this? If not, can anyone point me to a
>> good tutorial for writing apache filters?
>
> Sure.
> http://perl.apache.org/docs/2.0/user/handlers/filters.html
>
> ;-)
>
> (Note: that's not as silly as it sounds. As language, perl and PHP are
> reasonably close.  And since mod_perl is very closely integrated into Apache
> (much more than mod_php), what you will read there will give you a very good
> idea of how filters work in Apache)
>

Thanks, André, I'll take a look at the tutorial and see what I can come up with.

-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.edu/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] PHP script as Apache filter or "callback"

Posted by André Warnier <aw...@ice-sa.com>.
Brian Mearns wrote:
> I've got a PHP script that I want to call for every request under a
> certain location. Specifically, I want to alter/set the response
> headers using this script. I know headers can be set in other ways,
> but in this case, the heders are set using some fairly complex logic
> which I don't think can be done in the conf file directly, plus the
> PHP script will have some other side effects on the server.
> 
Maybe you'd have more chances here ? http://www.php.net/support.php

> Does anyone know of a way to do this? If not, can anyone point me to a
> good tutorial for writing apache filters?

Sure.
http://perl.apache.org/docs/2.0/user/handlers/filters.html

;-)

(Note: that's not as silly as it sounds. As language, perl and PHP are 
reasonably close.  And since mod_perl is very closely integrated into 
Apache (much more than mod_php), what you will read there will give you 
a very good idea of how filters work in Apache)


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: PHP script as Apache filter or "callback"

Posted by Brian Mearns <me...@gmail.com>.
On Sat, Mar 14, 2009 at 8:36 PM, Nicholas Sherlock <n....@gmail.com> wrote:
> Brian Mearns wrote:
>>
>> I've got a PHP script that I want to call for every request under a
>> certain location. Specifically, I want to alter/set the response
>> headers using this script. I know headers can be set in other ways,
>> but in this case, the heders are set using some fairly complex logic
>> which I don't think can be done in the conf file directly, plus the
>> PHP script will have some other side effects on the server.
>>
>> Does anyone know of a way to do this? If not, can anyone point me to a
>> good tutorial for writing apache filters?
>
> You might try PHP's auto_prepend_file:
>
>  auto_prepend_file  string
>
>    Specifies the name of a file that is automatically parsed before the main
> file. The file is included as if it was called with the require() function,
> so include_path is used.
>
>    The special value none disables auto-prepending.
>
> This allows you to run some PHP code before any script in the directory you
> set it for is run. It will only work for documents which PHP is set to
> parse, of course, so it won't help out for requests for other objects like
> images.
>
> Cheers,
> Nicholas Sherlock

Thanks for all the feedback, I think writing a custom Apache filter is
my best bet.

Thanks, again!
-Brian


-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.edu/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: PHP script as Apache filter or "callback"

Posted by Nicholas Sherlock <n....@gmail.com>.
Brian Mearns wrote:
> I've got a PHP script that I want to call for every request under a
> certain location. Specifically, I want to alter/set the response
> headers using this script. I know headers can be set in other ways,
> but in this case, the heders are set using some fairly complex logic
> which I don't think can be done in the conf file directly, plus the
> PHP script will have some other side effects on the server.
> 
> Does anyone know of a way to do this? If not, can anyone point me to a
> good tutorial for writing apache filters?

You might try PHP's auto_prepend_file:

   auto_prepend_file  string

     Specifies the name of a file that is automatically parsed before 
the main file. The file is included as if it was called with the 
require() function, so include_path is used.

     The special value none disables auto-prepending.

This allows you to run some PHP code before any script in the directory 
you set it for is run. It will only work for documents which PHP is set 
to parse, of course, so it won't help out for requests for other objects 
like images.

Cheers,
Nicholas Sherlock


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org