Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check memcached's capacity using php

Tags:

php

memcached

Not sure how to determine memcached's capacity (how full it is) using php. Can't seem to find any documentation on it either... Any ideas/suggestions?

like image 710
paradox870 Avatar asked Dec 05 '25 01:12

paradox870


2 Answers

Use getStats:

$m = new Memcached();
$m->addServer('localhost', 11211);

$stats = $m->getStats();
echo 'Capacity: ' . $stats['bytes'] . '/' . $stats['limit_maxbytes'] . ' Bytes';
like image 106
phihag Avatar answered Dec 07 '25 16:12

phihag


I actually kept looking around - the more useful info can come from:

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

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

This actually outputs more relevant info based on the way memcached allocates memory.

like image 42
paradox870 Avatar answered Dec 07 '25 15:12

paradox870



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!