]> git.openstreetmap.org Git - nominatim.git/blob - utils/blocks.php
rate limiting using memcache
[nominatim.git] / utils / blocks.php
1 #!/usr/bin/php -Cq
2 <?php
3
4         require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5         ini_set('memory_limit', '800M');
6
7         $aCMDOptions = array(
8                 "Manage service blocks / restrictions",
9                 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
10                 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
11                 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
12                 array('list', 'l', 0, 1, 0, 0, 'bool', 'List recent blocks'),
13                 array('delete', 'd', 0, 1, 0, 0, 'bool', 'Clear recent blocks list'),
14         );
15         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
16
17         $m = getBucketMemcache();
18         if (!$m)
19         {
20                 echo "ERROR: Bucket memcache is not configured\n";
21                 exit;
22         }
23
24         if ($aResult['list'])
25         {
26                 $aBlocks = getBucketBlocks();
27                 echo "\n";
28                 printf(" %-40s | %12s | %7s | %13s | %16s | %31s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Req Blocked", "Last Block Time");
29                 printf(" %'--40s | %'-12s | %'-7s | %'-13s | %'-16s | %'-31s\n", "", "", "", "", "", "");
30                 foreach($aBlocks as $sKey => $aDetails)
31                 {
32                         printf(" %-40s | %12s | %7s | %13s | %16s | %31s\n", $sKey, $aDetails['totalBlocks'], (int)$aDetails['currentBucketSize'], $aDetails['lastRequestBlocked']?'Y':'N', $aDetails['currentlyBlocked']?'Y':'N', date("r", $aDetails['lastBlockTimestamp']));
33                 }
34                 echo "\n";
35         }
36
37         if ($aResult['delete'])
38         {
39                 clearBucketBlocks();
40         }