X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/a723b942915a2f59bfc2c4d2e701ad720530627e..65ea0efe68fb52d0f591c964215866c9175adb6a:/lib/init-website.php diff --git a/lib/init-website.php b/lib/init-website.php index 40e4713e..bcf3ebf7 100644 --- a/lib/init-website.php +++ b/lib/init-website.php @@ -1,6 +1,17 @@ CONST_ConnectionBucket_WaitLimit && $fBucketVal < CONST_ConnectionBucket_BlockLimit) + { + $m = getBucketMemcache(); + $iCurrentSleeping = $m->increment('sleepCounter'); + if (false === $iCurrentSleeping) + { + $m->add('sleepCounter', 0); + $iCurrentSleeping = $m->increment('sleepCounter'); + } + if ($iCurrentSleeping >= CONST_ConnectionBucket_MaxSleeping || isBucketSleeping($aBucketKeys)) + { + // Too many threads sleeping already. This becomes a hard block. + $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_BlockLimit, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit); + } + else + { + setBucketSleeping($aBucketKeys, true); + sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate); + $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit); + setBucketSleeping($aBucketKeys, false); + } + $m->decrement('sleepCounter'); + } + if (strpos(CONST_BlockedIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false || $fBucketVal >= CONST_ConnectionBucket_BlockLimit) { echo "Your IP has been blocked. \n"; @@ -25,9 +60,5 @@ exit; } - if ($fBucketVal > CONST_ConnectionBucket_WaitLimit) - { - sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate); - } - header('Content-type: text/html; charset=utf-8'); +