I came up with this:
if($prog->memcache) { $r = $prog->memcache->get("ratelimit:{$_SERVER['REMOTE_ADDR']}"); if(!empty($r)) $prog->errorClose('This IP has been flagged for potential abuse.'); } foo(); // the thing we're rate limiting... if($prog->memcache) $prog->memcache->set("ratelimit:{$_SERVER['REMOTE_ADDR']}", 1, 0, 5);
Any thought on this, would it be beneficial to sleep for a few seconds if the IP is found in Memcached?