]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/init-website.php
if doing structured query limit the types of osm place returned
[nominatim.git] / lib / init-website.php
index 40e4713e21c1c6261fd12910d239c880d522a402..445bbc7ced2e5048f31766c78f6d0b40225c478f 100644 (file)
                        (defined('CONST_ConnectionBucket_PageType')?constant('CONST_ConnectionBucket_Cost_'.CONST_ConnectionBucket_PageType):1) + user_busy_cost(),
                        CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
 
+       if ($fBucketVal > 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)
+               {
+                       // Too many threads sleeping already.  This becomes a hard block.
+                       $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_BlockLimit, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
+               }
+               else
+               {
+                       sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate);
+                       $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
+               }
+               $m->decrement('sleepCounter');
+       }
+
        if (strpos(CONST_BlockedIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false || $fBucketVal >= CONST_ConnectionBucket_BlockLimit)
        {
                echo "Your IP has been blocked. \n";
@@ -25,9 +47,4 @@
                exit;
        }
 
-       if ($fBucketVal > CONST_ConnectionBucket_WaitLimit)
-       {
-               sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate);
-       }
-
        header('Content-type: text/html; charset=utf-8');