Memcache::getExtendedStats

(PECL memcache >= 2.0.0)

Memcache::getExtendedStats缓存服务器池中所有服务器统计信息

说明

Memcache::getExtendedStats(string $type = ?, int $slabid = ?, int $limit = 100): array

Memcache::getExtendedStats() 返回一个二维关联数据的服务器统计信息。数组的key由host:port方式 组成,无效的服务器返回的统计信息被设置为false,同样的,你可以使用函数 memcache_get_extended_stats()

注意:

这个函数在 Memcache 2.0.0 版本加入。

注意:

(译注)获取 Memcache 内所有数据方法:首先使用 getExtendedStats('slabs') 获取到每个服务器上活动 slabs 分块的 id, 然后 使用 getExtendedStats('cachedump', $slabid, $limit) 来获取每个 slab 里面缓存的项,其中 $slabid 是 slab 分块 id, $limit 指 期望获取其中的多少条记录。

参数

type

期望抓取的统计信息类型,可以使用的值有 {reset, malloc, maps, cachedump, slabs, items, sizes}。 通过 memcached 协议指定这些附加参数是为了方便 memcache 开发者(检查其中的变动)。

slabid

用于与参数 type 联合从指定 slab 分块拷贝数据,cachedump 命令会完全占用服务器通常用于 比较严格的调试。

limit

用于和参数type联合来设置 cachedump 时从服务端获取的实体条数。

警告

出于安全原因,cachedump stat 类型已经从 memcached 守护程序中移除。

返回值

返回一个二维关联数组的服务器统计信息或者在失败时返回 false

示例

示例 #1 Memcache::getExtendedStats() 示例

<?php
$memcache_obj
= new Memcache;
$memcache_obj->addServer('memcache_host', 11211);
$memcache_obj->addServer('failed_host', 11211);

$stats = $memcache_obj->getExtendedStats();
print_r($stats);
?>

以上示例会输出:

Array
(
    [memcache_host:11211] => Array
        (
            [pid] => 3756
            [uptime] => 603011
            [time] => 1133810435
            [version] => 1.1.12
            [rusage_user] => 0.451931
            [rusage_system] => 0.634903
            [curr_items] => 2483
            [total_items] => 3079
            [bytes] => 2718136
            [curr_connections] => 2
            [total_connections] => 807
            [connection_structures] => 13
            [cmd_get] => 9748
            [cmd_set] => 3096
            [get_hits] => 5976
            [get_misses] => 3772
            [bytes_read] => 3448968
            [bytes_written] => 2318883
            [limit_maxbytes] => 33554432
        )

    [failed_host:11211] => false
)

参见

添加备注

用户贡献的备注 5 notes

up
8
manmca dot 2280 at gmail dot com
14 years ago
Get lists of all the keys stored in memcache server....

<?php
/**
* Function to get all memcache keys
* @author Manish Patel
* @Created: 28-May-2010
*/
function getMemcacheKeys() {

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect to memcache server");

$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');
$items = $memcache->getExtendedStats('items');
foreach(
$allSlabs as $server => $slabs) {
foreach(
$slabs AS $slabId => $slabMeta) {
$cdump = $memcache->getExtendedStats('cachedump',(int)$slabId);
foreach(
$cdump AS $keys => $arrVal) {
foreach(
$arrVal AS $k => $v) {
echo
$k .'<br>';
}
}
}
}
}
//EO getMemcacheKeys()
?>

Hope it helps....
up
3
oushunbao at 163 dot com
13 years ago
Get lists of all the keys stored in memcache server....

<?php
/**
* Function to get all memcache keys
* @author Manish Patel
* @Created: 28-May-2010
* @modified: 16-Jun-2011
*/
function getMemcacheKeys() {

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect to memcache server");

$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');
$items = $memcache->getExtendedStats('items');
foreach(
$allSlabs as $server => $slabs) {
foreach(
$slabs AS $slabId => $slabMeta) {
$cdump = $memcache->getExtendedStats('cachedump',(int)$slabId);
foreach(
$cdump AS $keys => $arrVal) {
if (!
is_array($arrVal)) continue;
foreach(
$arrVal AS $k => $v) {
echo
$k .'<br>';
}
}
}
}
}
//EO getMemcacheKeys()
?>

copy from up, but fix a warning
i only add one line: if (!is_array($arrVal)) continue;
up
1
Anonymous
6 years ago
the latest updated version:

function getMemcacheKeys() {

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect to memcache server");

$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');
foreach($allSlabs as $server => $slabs) {
foreach($slabs AS $slabId => $slabMeta) {
if (!is_int($slabId)) { continue; }
$cdump = $memcache->getExtendedStats('cachedump',(int)$slabId);
foreach($cdump AS $keys => $arrVal) {
if (!is_array($arrVal)) continue;
foreach($arrVal AS $k => $v) {
$list[] = $k;
}
}
}
}
return $list;
}
up
0
jcastromail at yahoo dot es
7 years ago
" The cachedump stat type has been removed from the memcached daemon due to security reasons. "

To the date, the version 1.4.5_4_gaa7839e (windows 64bits) still supports the command cachedump that its highly important to returns the keys stored.
up
0
eithed at gmail
8 years ago
In response to manmca dot 2280 at gmail dot com

This function makes the memcached read only, at least with the most recent version of PECL memcache (3.0.8) and most recent version of memcache (1.4.21), so if you're relying on this to overwrite / remove only certain keys you're in for a nasty suprise
To Top