note 125238 added to memcached.getallkeys

From: Date: Mon, 03 Aug 2020 06:55:56 +0000
Subject: note 125238 added to memcached.getallkeys
Groups: php.notes 
Request: Send a blank email to php-notes+get-214921@lists.php.net to get a copy of this message
The right way to dump slab keys seems to be by using lru_crawler metadump instead of stats cachedump, see https://github.com/memcached/memcached/issues/405 <?php function getAllKeys(string $host, int $port): array { $sock = fsockopen($host, $port, $errno, $errstr); if ($sock === false) { throw new Exception("Error connection to server {$host} on port {$port}: ({$errno}) {$errstr}"); } if (fwrite($sock, "stats items\n") === false) { throw new Exception("Error writing to socket"); } $slabCounts = []; while (($line = fgets($sock)) !== false) { $line = trim($line); if ($line === 'END') { break; } // STAT items:8:number 3 if (preg_match('!^STAT items:(\d+):number (\d+)$!', $line, $matches)) { $slabCounts[$matches[1]] = (int)$matches[2]; } } foreach ($slabCounts as $slabNr => $slabCount) { if (fwrite($sock, "lru_crawler metadump {$slabNr}\n") === false) { throw new Exception('Error writing to socket'); } $count = 0; while (($line = fgets($sock)) !== false) { $line = trim($line); if ($line === 'END') { break; } // key=foobar exp=1596440293 la=1596439293 cas=8492 fetch=no cls=24 size=14908 if (preg_match('!^key=(\S+)!', $line, $matches)) { $allKeys[] = $matches[1]; $count++; } } // if ($count !== $slabCount) { // throw new Exception("Surprise, got {$count} keys instead of {$slabCount} keys"); // } } if (fclose($sock) === false) { throw new Exception('Error closing socket'); } return $allKeys; } ---- Server IP: 45.112.84.4 Probable Submitter: 103.51.166.36 (proxied: 193.230.233.253) ---- Manual Page -- http://php.net/manual/en/memcached.getallkeys.php Edit -- https://master.php.net/note/edit/125238 Del: integrated -- https://master.php.net/note/delete/125238/integrated Del: useless -- https://master.php.net/note/delete/125238/useless Del: bad code -- https://master.php.net/note/delete/125238/bad+code Del: spam -- https://master.php.net/note/delete/125238/spam Del: non-english -- https://master.php.net/note/delete/125238/non-english Del: in docs -- https://master.php.net/note/delete/125238/in+docs Del: other reasons-- https://master.php.net/note/delete/125238 Reject -- https://master.php.net/note/reject/125238 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214921) next »