PHP Conference Japan 2024

Memcache::getExtendedStats

(PECL memcache >= 2.0.0)

Memcache::getExtendedStats從集區中的所有伺服器取得統計資訊

描述

Memcache::getExtendedStats(字串 $type = ?, 整數 $slabid = ?, 整數 $limit = 100): 陣列

Memcache::getExtendedStats() 會傳回一個二維關聯陣列,其中包含伺服器統計資訊。陣列鍵值對應於伺服器的主機:埠號,值則包含個別伺服器的統計資訊。失敗的伺服器,其對應的項目會設定為 false。您也可以使用 memcache_get_extended_stats() 函式。

注意:

此函式已加入 Memcache 2.0.0 版。

參數

type

要擷取的統計資訊類型。有效值為 {reset, malloc, maps, cachedump, slabs, items, sizes}。根據 memcached 協定規格,這些額外參數「為了 memcache 開發人員的方便,可能會有所變更」。

slabid

與設定為 cachedump 的 type 一起使用,以識別要從哪個 slab 傾印。cachedump 命令會佔用伺服器,嚴格來說僅供偵錯使用。

limit

與設定為 cachedump 的 type 一起使用,以限制要傾印的項目數量。

警告

由於安全性考量,cachedump 統計類型已從 memcached daemon 中移除。

傳回值

傳回伺服器統計資訊的二維關聯陣列,失敗時則傳回 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 則註解

9
manmca dot 2280 at gmail dot com
14 年前
取得 memcache 伺服器中儲存的所有鍵值清單....

<?php
/**
* 取得所有 memcache 鍵值的函式
* @author Manish Patel
* @Created: 28-May-2010
*/
function getMemcacheKeys() {

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("無法連線至 memcache 伺服器");

$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()
?>

希望對您有幫助....
3
oushunbao at 163 dot com
13 年前
取得 memcache 伺服器中儲存的所有鍵值清單....

<?php
/**
* 取得所有 memcache 的鍵值 (key) 的函式
* @author Manish Patel
* @Created: 2010-05-28
* @modified: 2011-06-16
*/
function getMemcacheKeys() {

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("無法連線至 memcache 伺服器");

$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()
?>

從上方複製,但修正了一個警告
我只新增了一行: if (!is_array($arrVal)) continue;
1
匿名
6 年前
最新的更新版本

function getMemcacheKeys() {

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("無法連線至 memcache 伺服器");

$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;
}
0
jcastromail at yahoo dot es
7 年前
"由於安全考量,快取傾印 (cachedump) 統計類型已從 memcached 精靈程式中移除。"

至今,版本 1.4.5_4_gaa7839e (windows 64 位元) 仍然支援 cachedump 命令,它對於傳回儲存的鍵值非常重要。
0
eithed at gmail
8 年前
回覆 manmca dot 2280 at gmail dot com

此函式會使 memcached 變成唯讀,至少在最新版本的 PECL memcache (3.0.8) 和最新版本的 memcache (1.4.21) 上是如此,因此如果您依賴此函式來覆寫/移除某些鍵值,您會遇到難題
To Top