]> git.openstreetmap.org Git - nominatim.git/blob - utils/blocks.php
e1dfb5909c9a06fa60352deca23d711a1023b6a7
[nominatim.git] / utils / blocks.php
1 #!/usr/bin/php -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(" %-40s | %12s | %7s | %13s | %31s | %8s\n", $sKey, $aDetails['totalBlocks'], 
36             (int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N', 
37             date("r", $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N');
38     }
39     echo "\n";
40 }
41
42 if ($aResult['delete']) {
43     $m->set('sleepCounter', 0);
44     clearBucketBlocks();
45 }
46
47 if ($aResult['flush']) {
48     $m->flush();
49 }