Understanding Apache RewriteMap with RewriteLock

I started developing a fairly powerful LAMP application. The original developer used the .htaccess file with RewriteMap and a PHP script to handle certain application conditions.

In particular, when certain subdomain templates are requested by the client, RewriteMap catches them and sends them to the appropriate application module.

I am quite comfortable with typical mod_rewrite redirects, and I think I have a basic RewriteMap concept; but I'm struggling to find some decent documentation on how RewriteLock works. According to Apache docs:

This directive sets the file name for the synchronization lock file that mod_rewrite must associate with RewriteMap programs. Install this lock file on a local path (not on a device connected to NFS) if you want to use a rewriting card. This is not required for other types of rewriting cards.

But this is still a little vague for me. What is the purpose and function of RewriteLock and how does it work?

+8
apache mod-rewrite lamp
source share
2 answers

RewriteLock is used with the prg: keyword. RewriteMap can be used with several keywords to use text files ( txt: , a hash of files ( dbm: , randomized text ( rnd: or external matching scripts (this is prg: . In this mode, an external script is launched when apache starts. Then, for every incoming request, when mod-rewrite calls prg: apache sends input to this script and reads the output stream to get the value.

RewriteLock should be used in this case to prevent parallel requests (so parallel inputs to this external process) in order to mix responses on this standard process output. This is a locking mechanism (file, given path, which is a classic token, only one user) to ensure serialization of calls to this external script mapping. IMHO, it should be transparently applied by mod-rewrite when using prg: since I never found a prg case where this locking function is optional .

Edit:

In fact, you can use external prg: without rewriteLock, if randomizing output is not a problem, that is, for this record you can get the answer that was given for another record, for example, in the script some advanced rnd :, your own round-robin service. But if the output should reflect the record, you need this semaphore, which, of course, can slow down the rewriting process.

So, if you use only hashmap or textmap, you do not need to install RewriteLock.

Edit:

You can find useful information about this thread , for example, the fact that the lock file only exists for a few milliseconds when apache calls prg and waits for a response.

Edit: The question is one strange fact:

Original dev used .htaccess file with RewriteMap

This is strange because RewriteMap cannot work with .htaccess.htaccess files - these are configuration entries that are read dynamically, and RewriteMap, as indicated here in the context of the line, can only be set in the main configuration or in VirtualHost configuration. It cannot be in a location, directory, or .htaccess. This will probably never work in .htaccess.

Now @puk asked for an example of using RewriteMap. Well, searching for β€œRewriteMap” in a stack overflow will show you some real-world examples:

  • here in the question
  • here is a list of examples in my answer
  • here is another
+3
source share

Apache freezes if you define multiple RewriteLock directives or use it in a VHOST configuration.

RewriteLock must be specified at the server configuration level and ONLY ONE. This lock file will be used by all prg cards. Therefore, if you want to use several prg cards, I suggest using the internal locking mechanism, for example, in PHP there is a flock function, and just ignore the apache warning that writes to the error log.

See here for more information: http://books.google.com/books?id=HUpTYMf8-aEC&lpg=PP1&pg=PA298#v=onepage&q&f=false

0
source share

All Articles