diff --git a/bin/memcacheSync.php b/bin/memcacheSync.php index 0b5ca9c85980c3c3b7558b4dda257c7cafe21b97..0dfdc31f4741b3b56961c9ea27e7e569ac3952a8 100755 --- a/bin/memcacheSync.php +++ b/bin/memcacheSync.php @@ -3,19 +3,19 @@ // Check that the memcache library is enabled -if(!class_exists('Memcache') && !class_exists('Memcached')) { - echo("Error: the memcached (or memcache) PHP extension appears to be unavailable.\n"); - echo("\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("\n"); - if(is_executable('/usr/sbin/phpenmod')) { - 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 memcache\n"); - } - - exit(1); +if (!class_exists('Memcache') && !class_exists('Memcached')) { + echo "Error: the memcached (or memcache) PHP extension appears to be unavailable.\n"; + echo "\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 "\n"; + if (is_executable('/usr/sbin/phpenmod')) { + 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 memcache\n"; + } + + exit(1); } // This is the base directory of the SimpleSAMLphp installation @@ -38,25 +38,24 @@ $stats = \SimpleSAML\Memcache::getRawStats(); $keys = []; foreach ($stats as $group) { foreach ($group as $server => $state) { - if ($state === false) { - echo("WARNING: Server ".$server." is down.\n"); + echo "WARNING: Server ".$server." is down.\n"; $warnServerDown++; continue; } $items = $state['curr_items']; - echo("Server ".$server." has ".$items." items.\n"); + echo "Server ".$server." has ".$items." items.\n"; $serverKeys = getServerKeys($server); $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); -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; $sync = 0; @@ -70,20 +69,20 @@ foreach ($keys as $key) { } -echo("Synchronization done.\n"); -echo($sync." keys in sync.\n"); +echo "Synchronization done.\n"; +echo $sync." keys in sync.\n"; if ($skipped > 0) { - echo($skipped." keys skipped.\n"); - echo("Keys are skipped because they are either expired, or are of a type unknown\n"); - echo("to SimpleSAMLphp.\n"); + echo $skipped." keys skipped.\n"; + echo "Keys are skipped because they are either expired, or are of a type unknown\n"; + echo "to SimpleSAMLphp.\n"; } 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) { - 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) $host = $server[0]; $port = (int) $server[1]; - echo("Connecting to: ".$host.":".$port."\n"); + echo "Connecting to: ".$host.":".$port."\n"; $socket = fsockopen($host, $port); - echo("Connected. Finding keys.\n"); + echo "Connected. Finding keys.\n"; 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); } @@ -127,9 +126,8 @@ function getServerKeys($server) // Dump keys in slabs $keys = []; foreach ($slabs as $slab) { - 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); } @@ -149,17 +147,17 @@ function getServerKeys($server) if (preg_match('/^ITEM (.*) \[\d+ b; \d+ s\]/', $line, $matches)) { $keys[] = $matches[1]; } else { - echo("Unknown result from cache dump: ".$line."\n"); + echo "Unknown result from cache dump: ".$line."\n"; } } if ($resultSize > 1900000 || count($keys) >= 1000000) { - echo("WARNING: Slab ".$slab." on server ".$host.":".$port. - " may have contained more keys than we were told about.\n"); + echo "WARNING: Slab ".$slab." on server ".$host.":".$port. + " may have contained more keys than we were told about.\n"; $GLOBALS['warnBigSlab'] += 1; } } - echo("Found ".count($keys)." key(s).\n"); + echo "Found ".count($keys)." key(s).\n"; fclose($socket); return $keys;