$bin){ list($host, $port) = explode(':', $server); if (@$m->connect($host, $port)){ $bins[$bin][] = $m->getStats(); $m->close(); } else { die ("Could not connect to memcached server on $host:$port\n"); } } $stats = array(); foreach ($bins as $bin => $vals){ foreach(array('curr_items', 'total_items', 'get_hits', 'get_misses', 'bytes', 'limit_maxbytes') as $item){ foreach($vals as $val){ $stats[$bin][$item] += $val[$item]; } } } print "\n". sprintf("%-25s", bin) . sprintf("%-20s", 'current/total') . sprintf("%-15s", 'size used/max') . sprintf("%-20s", "hit rate") . "\n"; print str_repeat('-', 80) . "\n"; foreach ($stats as $bin => $items){ if ( $items['get_hits'] + $items['get_misses'] != 0){ $hit = round($items['get_hits'] / ($items['get_hits'] + $items['get_misses']) * 100, 2) . ' %'; } else { $hit = '0 %'; } $mb = round($items['bytes'] / 1048576, 3); $max = round($items['limit_maxbytes'] / 1048576, 3) . ' MB'; print sprintf("%-25s", $bin) . sprintf("%-20s", $items['curr_items'] . '/' . $items['total_items']) . sprintf("%-15s", $mb .'/'. $max ) . sprintf("%-20s", $hit) . "\n"; }