PHP 8.4.6 Released!

Memcache::getExtendedStats

(PECL memcache >= 2.0.0)

Memcache::getExtendedStatsObtém estatísticas de todos os servidores no pool

Descrição

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

Memcache::getExtendedStats() retorna um array associativo bidimensional com estatísticas do servidor. As chaves do array correspondem a host:porta do servidor e os valores contêm as estatísticas individuais do servidor. Um servidor com falha terá sua entrada correspondente definida como false. Também pode ser usada a função memcache_get_extended_stats().

Nota:

Esta função foi adicionada ao Memcache versão 2.0.0.

Parâmetros

type

O tipo de estatística a ser buscada. Os valores válidos são {reset, malloc, maps, cachedump, slabs, items, sizes}. De acordo com a especificação do protocolo memcached, esses argumentos adicionais "estão sujeitos a alterações para a conveniência dos desenvolvedores do memcache".

slabid

Usado em conjunto com type definido como "cachedump" para identificar o "slab" a partir do qual os dados serão despejados. O comando "cachedump" pode sobrecarregar o servidor e deve ser usado estritamente para propósitos de depuração.

limit

Usado em conjunto com type definido como "cachedump" para limitar o número de entradas a serem despejadas.

Aviso

O tipo de estatística "cachedump" foi removido do daemon memcached por motivos de segurança.

Valor Retornado

Retorna um array associativo bidimensional de estatísticas do servidor ou false em caso de falha.

Exemplos

Exemplo #1 Exemplo de 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);
?>

O exemplo acima produzirá:

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
)

Veja Também

adicione uma nota

Notas Enviadas por Usuários (em inglês) 5 notes

up
9
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
8 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