Created
October 7, 2013 04:55
-
-
Save kwon37xi/6862715 to your computer and use it in GitHub Desktop.
Memcached Key list viewer PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$server = "localhost"; | |
$port = 11211; | |
/** | |
* Taken directly from memcache PECL source | |
* | |
* http://pecl.php.net/package/memcache | |
* | |
*/ | |
function sendMemcacheCommand($server,$port,$command){ | |
$s = @fsockopen($server,$port); | |
if (!$s){ | |
die("Cant connect to:".$server.':'.$port); | |
} | |
fwrite($s, $command."\r\n"); | |
$buf=''; | |
while ((!feof($s))) { | |
$buf .= fgets($s, 256); | |
if (strpos($buf,"END\r\n")!==false){ // stat says end | |
break; | |
} | |
if (strpos($buf,"DELETED\r\n")!==false || strpos($buf,"NOT_FOUND\r\n")!==false){ // delete says these | |
break; | |
} | |
if (strpos($buf,"OK\r\n")!==false){ // flush_all says ok | |
break; | |
} | |
} | |
fclose($s); | |
return ($buf); | |
} | |
$string = sendMemcacheCommand($server, $port, "stats items"); | |
$lines = explode("\r\n", $string); | |
$slabs = array(); | |
foreach($lines as $line) { | |
if (preg_match("/STAT items:([\d]):/", $line, $matches) == 1) { | |
if (isset($matches[1])) { | |
if (!in_array($matches[1], $slabs)) { | |
$slabs[] = $matches[1]; | |
$string = sendMemcacheCommand($server, $port, "stats cachedump " . $matches[1] . " 100"); | |
echo "Slab # " . $matches[1] . "\n"; | |
preg_match_all("/ITEM (.*?) /", $string, $matches); | |
var_dump($matches[1]); | |
echo "=====================================\n"; | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From http://lzone.de/dump%20memcache%20keys