Small addition to Apache 1.3.x

php.internals

Manuel Vázquez Acosta

21 years ago
Hi internals: I made an addition to Apache 1.3.x SAPI; and I would like you to take a look at it, so you can evaluate if it has a chance to go official. Basically, the new feature lets Apache users to set a PHP Script Handler, this is, for each request made to the server the PHP Script Handler is execute, the only necessary configuration stuff looks like this: <VirtualHost *> ... classical stuff ... php_sethandler /path/to/handler.php SetHandler application/x-httpd-php </VirtualHost> I made patches for both PHP 4.3.8 and 4.3.9, they are in: http://www.chasqui.cu/staff/manu/2004/php-4.3.8-m3.patch.bz2 http://www.chasqui.cu/staff/manu/2004/php-4.3.9-m3.patch.bz2 (A list of few motivations for this add is in http://www.chasqui.cu/staff/manu/2004/apache.sapi.motivations.txt) I have tested both patches only on a Linux (LFS 5.1.1) with Apache 1.3.31. Some things I have not done yet: 1. Currently, I'm not making any checks for the PHP Script Handler file to exists. I will. 2. I have not modified the config.m4, I'm not familiar with M4, so I need to read some docs before I can do it. 3. I have not tested the DISABLE_SCRIPT_HANDLER branch yet, this is, compile with -DDISABLE_SCRIPT_HANDLER in order not to include the new feature. I would like to receive feedback on this. I'm very new to C coding, and I would like some of you to test it. Please don't let me holding on. Regards, Manu.

Jason Garber

21 years ago
Hello Manuel, After reading your motivations, it seems to me that you need mod rewrite. from: http://httpd.apache.org/docs/mod/mod_rewrite.html "Welcome to mod_rewrite, the Swiss Army Knife of URL manipulation! This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, for instance server variables, environment variables, HTTP headers, time stamps and even external database lookups in various formats can be used to achieve a really granular URL matching. This module operates on the full URLs (including the path-info part) both in per-server context (httpd.conf) and per-directory context (.htaccess) and can even generate query-string parts on result. The rewritten result can lead to internal sub-processing, external request redirection or even to an internal proxy throughput." Check it out.
-- Best regards, Jason mailto:jason@ionzoft.com Wednesday, October 6, 2004, 9:45:23 PM, you wrote: MVA> Hi internals: MVA> I made an addition to Apache 1.3.x SAPI; and I would like you to take a look MVA> at it, so you can evaluate if it has a chance to go official. MVA> Basically, the new feature lets Apache users to set a PHP Script Handler, MVA> this is, for each request made to the server the PHP Script Handler is MVA> execute, the only necessary configuration stuff looks like this: MVA> <VirtualHost *> MVA> ... classical stuff ... MVA> php_sethandler /path/to/handler.php MVA> SetHandler application/x-httpd-php MVA> </VirtualHost> MVA> I made patches for both PHP 4.3.8 and 4.3.9, they are in: MVA> http://www.chasqui.cu/staff/manu/2004/php-4.3.8-m3.patch.bz2 MVA> http://www.chasqui.cu/staff/manu/2004/php-4.3.9-m3.patch.bz2 MVA> (A list of few motivations for this add is in MVA> http://www.chasqui.cu/staff/manu/2004/apache.sapi.motivations.txt) MVA> I have tested both patches only on a Linux (LFS 5.1.1) with Apache 1.3.31. MVA> Some things I have not done yet: MVA> 1. Currently, I'm not making any checks for the PHP Script Handler file to MVA> exists. I will. MVA> 2. I have not modified the config.m4, I'm not familiar with M4, so I need to MVA> read some docs before I can do it. MVA> 3. I have not tested the DISABLE_SCRIPT_HANDLER branch yet, this is, compile MVA> with -DDISABLE_SCRIPT_HANDLER in order not to include the new feature. MVA> I would like to receive feedback on this. I'm very new to C coding, and I MVA> would like some of you to test it. Please don't let me holding on. MVA> Regards, MVA> Manu.

Alan Knowles

21 years ago
Have you ever used mod_rewrite for anything complex? - it's a complete nightmare (unpredictable, almost impossible to debug..., uncomprehensible syntax.....) This looks like quite usefull. - a little cleaner than 404 redirecting, which is the other way it's done at present.. Regards Alan Jason Garber wrote:

George Schlossnagle

21 years ago
On Oct 6, 2004, at 10:02 PM, Alan Knowles wrote:
> Have you ever used mod_rewrite for anything complex? - it's a complete > nightmare (unpredictable, almost impossible to debug..., > uncomprehensible syntax.....) > > This looks like quite usefull. - a little cleaner than 404 > redirecting, which is the other way it's done at present..
I've used mod_rewrite for complex things. It is nasty. This however is a trivial application of it. George

Sean Coates

21 years ago
Alan Knowles wrote:
> Have you ever used mod_rewrite for anything complex? - it's a complete > nightmare (unpredictable, almost impossible to debug..., > uncomprehensible syntax.....) > > This looks like quite usefull. - a little cleaner than 404 redirecting, > which is the other way it's done at present..
To throw my 2cents in: I implemented a mod_rewrite scheme for docweb (cvs:/docweb) and it was also a bit nasty (even though it was simple). 404 redirecting (my original idea) failed because it seems Apache discards POST data when calling the result of an ErrorDocument handler. This patch seems like it might have solved my problem in a much less hackish manner, if it were widespread (ie, in core). S

Manuel Vázquez Acosta

21 years ago
I'm starting to read mod_rewrite doc [1]; but in my current state of not knowing, my mind starts popping questions like: Does this URL to URL mapping will leave original URI visible somewhere or somehow to PHP (ie. $_SERVER['REQUEST_URI'])? Does it leave the original PATH_TRANSLATED visible to PHP? These Q are very important; if the answer is No, then I would have to make some tricks to obtain the original URI and PATH_TRANSLATED. My code would rely on this. Does it do its job by sub-requesting the mapped URL? (I think this a thumb question; otherwise mod_rewrite would work like a redirect, but let's keep this Q) The 404 solution doesn't fit my needs. I want EVERYTHING (even if the URI is resolved to an existing file) to get though the PHP Script Handler. Besides: "While URL manipulations in per-server context are really fast and efficient, per-directory rewrites are slow and inefficient due to this chicken and egg problem. But on the other hand this is the only way mod_rewrite can provide (locally restricted) URL manipulations to the average user." [1] Others questions are now coming to my mind, so I think the time has come for me to finish reading the mod_rewrite doc. Thanks, (New stuff is always welcome) Manuel. [1] http://httpd.apache.org/docs/mod/mod_rewrite.html

Manuel Vázquez Acosta

21 years ago
The following was emailed to me and it worked fine for URL which resolved to an existing file, but it's failing to do so when otherwise the URL cannot be mapped to a physical file. However, the 2nd motivation on removing every bit of php from the sight of designers, seems not to be fullfilled right this way; problably more has to be done. BTW, I've just read the original URI is indeed passed to PHP:
>>>>>
Environment Variables This module keeps track of two additional (non-standard) CGI/SSI environment variables named SCRIPT_URL and SCRIPT_URI. These contain the logical Web-view to the current resource, while the standard CGI/SSI variables SCRIPT_NAME and SCRIPT_FILENAME contain the physical System-view. Notice: These variables hold the URI/URL as they were initially requested, i.e., before any rewriting. This is important because the rewriting process is primarily used to rewrite logical URLs to physical pathnames. Example: SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html SCRIPT_FILENAME=/u/rse/.www/index.html SCRIPT_URL=/u/rse/ SCRIPT_URI=http://en1.engelschall.com/u/rse/ <<<< The message follows: Hello Manuel, I am by no means an expert on mod-rewrite, but I have used it for doing what you are looking for. Here is one that we use to translate: http://domain.com/yourname to http://domain.com/vo/vsite/index.php?VSITTE_ID=yourname <VirtualHost 192.168.0.4> *** normal stuff *** RewriteEngine on RewriteRule ^/([0-9A-Za-z_.,-]+)$ /vo/vsite/index.php?VSITE_ID=$1 </VirtualHost> What this does is takes anything after the / and makes it into a query string that is then sent to /vo/vsite/index.php (the $1 is replaced by the regular expression match) I think what you want to do is this: RewriteRule ^/(.*) /foo/bar/handler.php/$1 or RewriteRule ^/(.*) /foo/bar/handler.php?PATH=$1 If this helps, or you find it to work, please post back to the list... I'll try to answer some questions below...
-- Best regards, Jason mailto:jason@ionzoft.com Wednesday, October 6, 2004, 11:53:26 PM, you wrote: MVA> I'm starting to read mod_rewrite doc [1]; but in my current state MVA> of not knowing, my mind starts popping questions like: MVA> Does this URL to URL mapping will leave original URI visible MVA> somewhere or somehow to PHP (ie. $_SERVER['REQUEST_URI'])? I think you have to do that how I described above. MVA> Does it leave the original PATH_TRANSLATED visible to PHP? Don't know MVA> These Q are very important; if the answer is No, then I would have MVA> to make some tricks to obtain the original URI and PATH_TRANSLATED. MVA> My code would rely on this. MVA> Does it do its job by sub-requesting the mapped URL? (I think this MVA> a thumb question; otherwise mod_rewrite would work like a redirect, MVA> but let's keep this Q) It does it all in the server, the browser never knew what happened. MVA> The 404 solution doesn't fit my needs. I want EVERYTHING (even if MVA> the URI is resolved to an existing file) to get though the PHP Script Handler. I think I showed you how to do that above MVA> Besides: "While URL manipulations in per-server context are really MVA> fast and efficient, per-directory rewrites are slow and inefficient MVA> due to this chicken and egg problem. But on the other hand this is MVA> the only way mod_rewrite can provide (locally restricted) URL MVA> manipulations to the average user." [1] MVA> Others questions are now coming to my mind, so I think the time has MVA> come for me to finish reading the mod_rewrite doc. MVA> Thanks, (New stuff is always welcome) Manuel. MVA> [1] http://httpd.apache.org/docs/mod/mod_rewrite.html

Manuel Vázquez Acosta

21 years ago
Oops, scratch this, I did something stupid in the httpd.conf, which make it not work for 404. "Manuel VáZquez Acosta" <manu@chasqui.cu> wrote in message news:20041007044946.82890.qmail@pb1.pair.com...
> The following was emailed to me and it worked fine for URL which resolved
to
> an existing file, but it's failing to do so when otherwise the URL cannot
be

Manuel Vázquez Acosta

21 years ago
I would like to know if some guy of the PHP Group has taken a look at this thread. Although it has been stated that one of the main motivations its fulfilled with mod_rewrite; it's not clear that mod_rewrite would help with the second motivation; and I think this tiny patch is slightly faster than mod_rewrite for per directory. So, any chances to go ahead? Regards, Manuel. "Manuel VáZquez Acosta" <manu@chasqui.cu> wrote in message news:20041007014658.17439.qmail@pb1.pair.com...
> Hi internals: > > I made an addition to Apache 1.3.x SAPI; and I would like you to take a
look
> at it, so you can evaluate if it has a chance to go official. > > Basically, the new feature lets Apache users to set a PHP Script Handler, > this is, for each request made to the server the PHP Script Handler is > execute, the only necessary configuration stuff looks like this: > > <VirtualHost *> > ... classical stuff ... > php_sethandler /path/to/handler.php > SetHandler application/x-httpd-php > </VirtualHost> > > I made patches for both PHP 4.3.8 and 4.3.9, they are in: > http://www.chasqui.cu/staff/manu/2004/php-4.3.8-m3.patch.bz2 > http://www.chasqui.cu/staff/manu/2004/php-4.3.9-m3.patch.bz2 > > (A list of few motivations for this add is in > http://www.chasqui.cu/staff/manu/2004/apache.sapi.motivations.txt) > > > I have tested both patches only on a Linux (LFS 5.1.1) with Apache 1.3.31. > > Some things I have not done yet: > > 1. Currently, I'm not making any checks for the PHP Script Handler file to > exists. I will. > > 2. I have not modified the config.m4, I'm not familiar with M4, so I need
to
> read some docs before I can do it. > > 3. I have not tested the DISABLE_SCRIPT_HANDLER branch yet, this is,
compile