returning a different response if memcache key is set

Atif Ghaffar atif.ghaffar at gmail.com
Wed Feb 4 03:34:00 MSK 2009


perhaps I can explain better with code.

on the php side its like this
            $memcache = new Memcache;
            if (!$memcache->connect("192.168.0.9", 11211) ) {
                return;
            }
            //$host is HTTP_HOST variable.

            $lock_key=$host.".lock";


            if ($memcache->get($host)) {
                $memcache->increment($host);
            } else {
                $memcache->set($host, 1, false, 60); # calculate how many
requests per minute, expire after 60seconds
            }
            $x=$memcache->get($host);
            if ($x>100) {
                $memcache->set($lock_key, 1, false, 60); # lock the domain
for 60 seconds
            }

on nginx side i would like

if memcache get($http_host . lock){
  redirect to another page
}


best regards






On Wed, Feb 4, 2009 at 1:11 AM, Atif Ghaffar <atif.ghaffar at gmail.com> wrote:

> Dear all,
>
> A day ago, we had a DDOS attack.
>
> To remedy that we have put some logic on the php application to check
> number of access on php per minute and if certain limit is matched do
> something like "print 'please try later' and exit"
>
> On the php side it will work fine but on the nginx side, it will still
> forward all the request to the php-cgi to get that response.
>
> What I would like to do in php side is something like
>
> if limit reached,
> key=hostname.locked, "Please try again later"
>
> on nginx side.
>
> If found memcached HTTP_HOST.locked, return someother file.
>
> is that do-able.
>
> best regards
>
>


-- 
best regards
Atif Ghaffar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20090204/e420a8f3/attachment.html>


More information about the nginx mailing list