Clickalicious\PhpMemAdmin\App::dumpEntries PHP Method

dumpEntries() protected method

Returns all entries for a passed slab (hostname & port) by passed namespace or all.
Author: Benjamin Carl ([email protected])
protected dumpEntries ( string $host, integer $port, string | null $namespace = null, boolean $flat = false ) : array
$host string The host (slab) to fetch items from
$port integer The port
$namespace string | null The namespace to filter on as string, otherwise NULL to fetch all
$flat boolean TRUE to return plain key/value pairs, FALSE to return meta-data as well
return array List of entries indexed by key
    protected function dumpEntries($host, $port, $namespace = null, $flat = false)
    {
        // Assume empty result
        $result = array();
        $client = $this->getMemcachedClient($host, $port, $this->getConfig()->timeout);
        // Fetch all keys and all values ...
        $allSlabs = $client->stats(Client::STATS_TYPE_SLABS);
        $items = $client->stats(Client::STATS_TYPE_ITEMS);
        if (isset($slabs['active_slabs']) === true) {
            unset($slabs['active_slabs']);
        }
        if (isset($slabs['total_malloced']) === true) {
            unset($slabs['total_malloced']);
        }
        foreach ($allSlabs as $slabId => $slabMeta) {
            $cachedump = $client->stats(Client::STATS_TYPE_CACHEDUMP, (int) $slabId, Client::CACHEDUMP_ITEMS_MAX);
            foreach ($cachedump as $key => $value) {
                if ($flat === true) {
                    $metaData = $client->gets(array($key), true);
                    $result[] = array('key' => $key, 'value' => $metaData[$key]['value'], 'cas' => $metaData[$key]['meta']['cas'], 'frames' => $metaData[$key]['meta']['frames'], 'flags' => $metaData[$key]['meta']['flags']);
                } else {
                    $result[$key] = array('raw' => $value, 'value' => $client->gets(array($key)), 'server' => $host . ':' . $port, 'slabId' => $slabId, 'age' => $items['items'][$slabId]['age']);
                }
            }
        }
        return $result;
    }