Skip to content
Snippets Groups Projects
Commit 2a775810 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

bin: PSR2

parent f9218078
No related branches found
No related tags found
No related merge requests found
...@@ -3,19 +3,19 @@ ...@@ -3,19 +3,19 @@
// Check that the memcache library is enabled // Check that the memcache library is enabled
if(!class_exists('Memcache') && !class_exists('Memcached')) { if (!class_exists('Memcache') && !class_exists('Memcached')) {
echo("Error: the memcached (or memcache) PHP extension appears to be unavailable.\n"); echo "Error: the memcached (or memcache) PHP extension appears to be unavailable.\n";
echo("\n"); echo "\n";
echo("This is most likely because PHP doesn't load it for the command line\n"); echo "This is most likely because PHP doesn't load it for the command line\n";
echo("version. You probably need to enable it somehow.\n"); echo "version. You probably need to enable it somehow.\n";
echo("\n"); echo "\n";
if(is_executable('/usr/sbin/phpenmod')) { if (is_executable('/usr/sbin/phpenmod')) {
echo("It is possible that running one of the following commands as root will fix it:\n"); echo "It is possible that running one of the following commands as root will fix it:\n";
echo(" phpenmod -s cli memcached\n"); echo " phpenmod -s cli memcached\n";
echo(" phpenmod -s cli memcache\n"); echo " phpenmod -s cli memcache\n";
} }
exit(1); exit(1);
} }
// This is the base directory of the SimpleSAMLphp installation // This is the base directory of the SimpleSAMLphp installation
...@@ -38,25 +38,24 @@ $stats = \SimpleSAML\Memcache::getRawStats(); ...@@ -38,25 +38,24 @@ $stats = \SimpleSAML\Memcache::getRawStats();
$keys = []; $keys = [];
foreach ($stats as $group) { foreach ($stats as $group) {
foreach ($group as $server => $state) { foreach ($group as $server => $state) {
if ($state === false) { if ($state === false) {
echo("WARNING: Server ".$server." is down.\n"); echo "WARNING: Server ".$server." is down.\n";
$warnServerDown++; $warnServerDown++;
continue; continue;
} }
$items = $state['curr_items']; $items = $state['curr_items'];
echo("Server ".$server." has ".$items." items.\n"); echo "Server ".$server." has ".$items." items.\n";
$serverKeys = getServerKeys($server); $serverKeys = getServerKeys($server);
$keys = array_merge($keys, $serverKeys); $keys = array_merge($keys, $serverKeys);
} }
} }
echo("Total number of keys: ".count($keys)."\n"); echo "Total number of keys: ".count($keys)."\n";
$keys = array_unique($keys); $keys = array_unique($keys);
echo("Total number of unique keys: ".count($keys)."\n"); echo "Total number of unique keys: ".count($keys)."\n";
echo("Starting synchronization.\n"); echo "Starting synchronization.\n" ;
$skipped = 0; $skipped = 0;
$sync = 0; $sync = 0;
...@@ -70,20 +69,20 @@ foreach ($keys as $key) { ...@@ -70,20 +69,20 @@ foreach ($keys as $key) {
} }
echo("Synchronization done.\n"); echo "Synchronization done.\n";
echo($sync." keys in sync.\n"); echo $sync." keys in sync.\n";
if ($skipped > 0) { if ($skipped > 0) {
echo($skipped." keys skipped.\n"); echo $skipped." keys skipped.\n";
echo("Keys are skipped because they are either expired, or are of a type unknown\n"); echo "Keys are skipped because they are either expired, or are of a type unknown\n";
echo("to SimpleSAMLphp.\n"); echo "to SimpleSAMLphp.\n";
} }
if ($warnServerDown > 0) { if ($warnServerDown > 0) {
echo("WARNING: ".$warnServerDown." server(s) down. Not all servers are synchronized.\n"); echo "WARNING: ".$warnServerDown." server(s) down. Not all servers are synchronized.\n";
} }
if ($warnBigSlab > 0) { if ($warnBigSlab > 0) {
echo("WARNING: ".$warnBigSlab." slab(s) may have contained more keys than we were told about.\n"); echo "WARNING: ".$warnBigSlab." slab(s) may have contained more keys than we were told about.\n";
} }
/** /**
...@@ -99,12 +98,12 @@ function getServerKeys($server) ...@@ -99,12 +98,12 @@ function getServerKeys($server)
$host = $server[0]; $host = $server[0];
$port = (int) $server[1]; $port = (int) $server[1];
echo("Connecting to: ".$host.":".$port."\n"); echo "Connecting to: ".$host.":".$port."\n";
$socket = fsockopen($host, $port); $socket = fsockopen($host, $port);
echo("Connected. Finding keys.\n"); echo "Connected. Finding keys.\n";
if (fwrite($socket, "stats slabs\r\n") === false) { if (fwrite($socket, "stats slabs\r\n") === false) {
echo("Error requesting slab dump from server.\n"); echo "Error requesting slab dump from server.\n";
exit(1); exit(1);
} }
...@@ -127,9 +126,8 @@ function getServerKeys($server) ...@@ -127,9 +126,8 @@ function getServerKeys($server)
// Dump keys in slabs // Dump keys in slabs
$keys = []; $keys = [];
foreach ($slabs as $slab) { foreach ($slabs as $slab) {
if (fwrite($socket, "stats cachedump ".$slab." 1000000\r\n") === false) { if (fwrite($socket, "stats cachedump ".$slab." 1000000\r\n") === false) {
echo("Error requesting cache dump from server.\n"); echo "Error requesting cache dump from server.\n";
exit(1); exit(1);
} }
...@@ -149,17 +147,17 @@ function getServerKeys($server) ...@@ -149,17 +147,17 @@ function getServerKeys($server)
if (preg_match('/^ITEM (.*) \[\d+ b; \d+ s\]/', $line, $matches)) { if (preg_match('/^ITEM (.*) \[\d+ b; \d+ s\]/', $line, $matches)) {
$keys[] = $matches[1]; $keys[] = $matches[1];
} else { } else {
echo("Unknown result from cache dump: ".$line."\n"); echo "Unknown result from cache dump: ".$line."\n";
} }
} }
if ($resultSize > 1900000 || count($keys) >= 1000000) { if ($resultSize > 1900000 || count($keys) >= 1000000) {
echo("WARNING: Slab ".$slab." on server ".$host.":".$port. echo "WARNING: Slab ".$slab." on server ".$host.":".$port.
" may have contained more keys than we were told about.\n"); " may have contained more keys than we were told about.\n";
$GLOBALS['warnBigSlab'] += 1; $GLOBALS['warnBigSlab'] += 1;
} }
} }
echo("Found ".count($keys)." key(s).\n"); echo "Found ".count($keys)." key(s).\n";
fclose($socket); fclose($socket);
return $keys; return $keys;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment