[Gllug] Slightly OT: Apache mod_throttle
Dave Cridland [Clues]
dave.cridland at clues.ltd.uk
Tue Aug 20 09:58:55 UTC 2002
Flash (saviour of the universe), sorry this one's late.
On Tue, 2002-08-13 at 09:55, Flash Wilson wrote:
> I am running apache 1.3.26 on redhat 6.2.
[shnip]
> I am told this may be because mod_throttle is a handler, and
> CGIs already use another one. Not sure tho - cant find anything
> to assist/confirm/deny on that.
That's true, I think, on Apache 1.3.x. Not so with Apache 2, though,
where everything's a filter, like ISAPI-land but more so. So you can, in
theory, have a CGI producing PHP code which gets executed to produce XML
which gets translated into HTML. Sick and twisted, eh?
> Anyone able to advise on a solution to throttle access to this
> CGI?
Apache 2 is probably your best bet, but you could also run a second
Apache instance to handle this CGI, and let that go bang happily,
couldn't you? Obviously on a different port, although you could proxy it
for the changeover.
> Blocking offenders is not an option, and rewriting the CGI is
> a last resort only (or I wouldnt bother asking).
Or something like this, which you could use to wrap errant scripts, and
which would tell the browser to come back later. Might be worth a shot.
#!/usr/bin/perl
$maxinstance = 5;
$name = "fish";
$myurl = "http://somehost.org/cgi-bin/this-script"; ## Not used, but
maybe should be.
$execed = 0;
for( $i=0; $i<$maxinstance; ++$i ) {
if( sysopen( TMP, "/var/lock/$name-$i", O_RDWR|O_CREAT|O_EXCL ) ) {
# fork, exec, wait - or system() if you're feeling frisky.
$execed = 1
close( TMP );
unlink( "/var/lock/$name-$i" );
break;
}
}
unless( $execed ) {
print "Content-Type: text/html\nRefresh: 10\n\n";
# Dunno whether "Refresh" header here works, or whether it needs URL,
or to be in a META tag, or both.
print "<html><head><title>Please Wait</title></head><body><h1>Please
Wait</h1><p>This resource is currently very busy. Your browser will
automatically retry after 10 seconds.</p></body></html>\n";
}
# END
Dave.
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list