Memcache::getExtendedStats
(PECL memcache >= 2.0.0)
Memcache::getExtendedStats — Get statistics from all servers in pool
Описание
$type
[, int $slabid
[, int $limit
= 100
]]] )
Memcache::getExtendedStats() returns a two-dimensional
associative array with server statistics. Array keys correspond to
host:port of server and values contain the individual server statistics.
A failed server will have its corresponding entry set to FALSE
.
You can also use the memcache_get_extended_stats() function.
Замечание:
This function has been added to Memcache version 2.0.0.
Список параметров
-
type
-
The type of statistics to fetch. Valid values are {reset, malloc, maps, cachedump, slabs, items, sizes}. According to the memcached protocol spec these additional arguments "are subject to change for the convenience of memcache developers".
-
slabid
-
Used in conjunction with
type
set to cachedump to identify the slab to dump from. The cachedump command ties up the server and is strictly to be used for debugging purposes. -
limit
-
Used in conjunction with
type
set to cachedump to limit the number of entries to dump.
The cachedump stat type has been removed from the memcached daemon due to security reasons.
Возвращаемые значения
Returns a two-dimensional associative array of server statistics or FALSE
on failure.
Примеры
Пример #1 Memcache::getExtendedStats() example
<?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() - Return version of the server
- Memcache::getStats() - Get statistics of the server
- Функция Memcache::add() - Add an item to the server
- Функция Memcache::addServer() - Add a memcached server to connection pool
- Функция Memcache::close() - Close memcached server connection
- Функция Memcache::connect() - Open memcached server connection
- Функция Memcache::decrement() - Decrement item's value
- Функция Memcache::delete() - Delete item from the server
- Функция Memcache::flush() - Flush all existing items at the server
- Функция Memcache::get() - Retrieve item from the server
- Функция Memcache::getExtendedStats() - Get statistics from all servers in pool
- Функция Memcache::getServerStatus() - Returns server status
- Функция Memcache::getStats() - Get statistics of the server
- Функция Memcache::getVersion() - Return version of the server
- Функция Memcache::increment() - Increment item's value
- Функция Memcache::pconnect() - Open memcached server persistent connection
- Функция Memcache::replace() - Replace value of the existing item
- Функция Memcache::set() - Store data at the server
- Функция Memcache::setCompressThreshold() - Enable automatic compression of large values
- Функция Memcache::setServerParams() - Changes server parameters and status at runtime
Коментарии
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....
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;
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
" 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.
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;
}