]> git.openstreetmap.org Git - nominatim.git/blob - utils/blocks.php
d2db17f0e9478b60e9dbc8e9f9faf8cb3a8e6c1b
[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                 $iCurrentSleeping = $m->get('sleepCounter');
27                 echo "\n Sleeping blocks count: $iCurrentSleeping\n";
28
29                 $aBlocks = getBucketBlocks();
30                 echo "\n";
31                 printf(" %-40s | %12s | %7s | %13s | %16s | %31s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Req Blocked", "Last Block Time");
32                 printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-16s-|-%'-31s\n", "", "", "", "", "", "");
33                 foreach($aBlocks as $sKey => $aDetails)
34                 {
35                         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']));
36                 }
37                 echo "\n";
38         }
39
40         if ($aResult['delete'])
41         {
42                 $m->set('sleepCounter', 0);
43                 clearBucketBlocks();
44         }