You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Josh Trutwin <jo...@trutwins.homeip.net> on 2007/12/07 13:11:00 UTC

Re: [users@httpd] [repost] PhP Rewrite Map File Problem

Hi - been a week, curious if anyone has any ideas?

Josh

On Fri, 30 Nov 2007 15:00:17 -0600
Josh Trutwin <jo...@trutwins.homeip.net> wrote:

> Hi - through some great help from this list (I'm looking at you
> Joshua Slive) I was able to setup a RewriteMap using a PhP program.
> After a couple months usage on a number of heavy sites we're
> noticing an odd inconsistent problem that causes ALL site requests
> to yeild this nasty error:
> 
> mod_rewrite: maximum number of internal redirects reached. Assuming
> configuration error. Use 'RewriteOptions MaxRedirects' to increase
> the limit if neccessary.
> 
> The program is called rewriter.php and starts with this directive:
> 
> RewriteLock '/tmp/rewrite.lock'
> RewriteMap rewriter prg:/usr/local/bin/rewriter.php
> 
> A site that wants to use this URL mapper has this in
> their .htaccess:
> 
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !-l
> RewriteRule .* ${rewriter:%{REQUEST_FILENAME}^%{REQUEST_URI}}
> [L,QSA,NS]
> 
> There are some other directives involved to 301 redirect old URL's
> to the new ones, but I don't think they are the problem.
> 
> The program source can be seen here:
> 
> http://batcave.intrcomm.net/rewriter.phps
> 
> In a nutshell what happens is the program parses stdin (which from
> the RewriteRule is the REQUEST_FILENAME followed by the REQUEST_URI)
> - from this information it can find the site's virtual host
> directory and load a file called _rewrite_map.php which is a simple
> php associated array containing for each page then URL should it map
> to. This works fine until someone updates that file through
> releasing pages on their site (via a CMS).  Occasionally, (maybe 5%
> of the time) when this file is updated the above error occurs on
> every request.  The ONLY way to fix this is to hard stop and start
> the server (a restart doesn't restart the php RewriteMap program)
> When the server is restarted, all works well - until the next time
> updating this file causes this problem.
> 
> I've added some logging where the URL is returned to the apache
> process:
> 
> if (DEBUG) { error_log("Map found for URI: $uri: $uri_under " .
> $map[$uri] . "\n", 3, '/tmp/rewriter.log'); }
> 
> fputs($stdout, $map[$uri] . "\n"); // tell RewriteRule the URL
> 
> Even when these maximum redirect errors are happening, the program
> is still logging the above using the correct URL - it's not having
> any problems accessing the map file.  I added some additional file
> locking (also to the program that updates the file) but that didn't
> help.
> 
> Someone at work here suggested that it might have to do with how
> stdin and stdout are defined, which makes sense so I'm trying that
> next but I wanted to see if any gurus on this list know of any
> strange RewriteMap bugs/gotchas like this.
> 
> PhP is 4.4 - apache is 1.3.37 - linux 2.4
> 
> Thanks - let me know if additional info is needed.
> 
> Josh
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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
> 

---------------------------------------------------------------------
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] [repost] PhP Rewrite Map File Problem

Posted by Vincent Bray <no...@gmail.com>.
On 07/12/2007, Josh Trutwin <jo...@trutwins.homeip.net> wrote:
> > to. This works fine until someone updates that file through
> > releasing pages on their site (via a CMS).  Occasionally, (maybe 5%
> > of the time) when this file is updated the above error occurs on
> > every request.  The ONLY way to fix this is to hard stop and start
> > the server (a restart doesn't restart the php RewriteMap program)
> > When the server is restarted, all works well - until the next time
> > updating this file causes this problem.

This could be the result of the included file being incomplete when
loaded. You could try an atomic operation when updating it, like
rewriting to a temporary file then rename() it over the old one.

-- 
noodl

---------------------------------------------------------------------
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