Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function sendMemcacheCommand($command){
- $server = "localhost";
- $port = 11211;
- $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) {
- break;
- }
- if (strpos($buf,"DELETED\r\n")!==false || strpos($buf,"NOT_FOUND\r\n")!==false) {
- break;
- }
- if (strpos($buf,"OK\r\n")!==false) {
- break;
- }
- }
- fclose($s);
- return ($buf);
- }
- function listKeys() {
- $res = array();
- $string = sendMemcacheCommand("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("stats cachedump " . $matches[1] . " 100");
- preg_match_all("/ITEM (.*?) /", $string, $matches);
- $res = array_merge($res, $matches[1]);
- }
- }
- }
- }
- return $res;
- }
- var_dump(listKeys());
- ?>
Add Comment
Please, Sign In to add comment