 |
mod_rewrite also allows us to fetch pass through instructions from a program.
Now consider this:
RewriteMap lb prg:/path/to/lb.pl
RewriteRule ^/(.+)$ ${lb:$1} [P,L]
Where lb.pl is a program that looks like this:
$| = 1;
while (<STDIN>) {
my $server=best_server($_);
print "http://$server/$_";
}
sub best_server {
# do something that is not too slow
my $r=shift;
}
Presumably best_server() does something simple like walk through
a list of back end servers or something more sophisticated like a lookup in
Berkeley DB hash to determine the most appropriate server for that request.
Whatever it does, make sure it does it fast lest the server is hung on a
lookup process that is slower than the request rate!
|