]> git.openstreetmap.org Git - nominatim.git/blob - utils/blocks.php
761ab9e4f004c11097093da1b16891dba8f1b6d5
[nominatim.git] / utils / blocks.php
1 #!@PHP_BIN@ -Cq
2 <?php
3
4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 ini_set('memory_limit', '800M');
7
8 $aCMDOptions
9  = array(
10     'Manage service blocks / restrictions',
11     array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
12     array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
13     array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
14     array('list', 'l', 0, 1, 0, 0, 'bool', 'List recent blocks'),
15     array('delete', 'd', 0, 1, 0, 0, 'bool', 'Clear recent blocks list'),
16     array('flush', '', 0, 1, 0, 0, 'bool', 'Flush all blocks / stats'),
17    );
18 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
19
20 $m = getBucketMemcache();
21 if (!$m) {
22     echo "ERROR: Bucket memcache is not configured\n";
23     exit;
24 }
25
26 if ($aResult['list']) {
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         printf(
36             " %-40s | %12s | %7s | %13s | %31s | %8s\n",
37             $sKey,
38             $aDetails['totalBlocks'],
39             (int)$aDetails['currentBucketSize'],
40             $aDetails['currentlyBlocked']?'Y':'N',
41             date('r', $aDetails['lastBlockTimestamp']),
42             $aDetails['isSleeping']?'Y':'N'
43         );
44     }
45     echo "\n";
46 }
47
48 if ($aResult['delete']) {
49     $m->set('sleepCounter', 0);
50     clearBucketBlocks();
51 }
52
53 if ($aResult['flush']) {
54     $m->flush();
55 }