文字

Memcache::getExtendedStats

(PECL memcache >= 2.0.0)

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

说明

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

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

Note:

这个函数在Memcache2.0.0版本加入。

Note:

(译注)获取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时从服务端获取的实体条数。

返回值

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

范例

Example #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
)

参见

  • Memcache::getVersion() - 返回服务器版本信息
  • Memcache::getStats() - 获取服务器统计信息

用户评论:

[#1] oushunbao at 163 dot com [2011-06-16 02:57:20]

Get lists of all the keys stored in memcache server....

<?php

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;

[#2] manmca dot 2280 at gmail dot com [2010-05-28 16:35:13]

Get lists of all the keys stored in memcache server....

<?php

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....

上一篇: 下一篇: