]> git.openstreetmap.org Git - nominatim.git/blob - utils/blocks.php
Reverted change on FIPS 35013 to remain ASCII
[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                 array('flush', '', 0, 1, 0, 0, 'bool', 'Flush all blocks / stats'),
15         );
16         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
17
18         $m = getBucketMemcache();
19         if (!$m)
20         {
21                 echo "ERROR: Bucket memcache is not configured\n";
22                 exit;
23         }
24
25         if ($aResult['list'])
26         {
27                 $iCurrentSleeping = $m->get('sleepCounter');
28                 echo "\n Sleeping blocks count: $iCurrentSleeping\n";
29
30                 $aBlocks = getBucketBlocks();
31                 echo "\n";
32                 printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Block Time", "Sleeping");
33                 printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s-|-%'-8s\n", "", "", "", "", "", "");
34                 foreach($aBlocks as $sKey => $aDetails)
35                 {
36                         printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", $sKey, $aDetails['totalBlocks'], 
37                                 (int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N', 
38                                 date("r", $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N');
39                 }
40                 echo "\n";
41         }
42
43         if ($aResult['delete'])
44         {
45                 $m->set('sleepCounter', 0);
46                 clearBucketBlocks();
47         }
48
49         if ($aResult['flush'])
50         {
51                 $m->flush();
52         }