MicronXD MicronXD - 1 year ago 66
PHP Question

Memcached PHP module: How can you tell if the connection failed?

in a php file, I have:

$m = new Memcached();
echo get_class($m);
echo "<br>";
echo $m->addServer('', 11211, 1);
$m->set("foo", "bar");

when run, around a half second later, I get:


If I stop memcached, after about 5 seconds, I get:


I was expecting something more like...


How do you know if you've successfully hit the memcached server or not? I was fully expecting it to be as simple as a return value from addServer... :(

Answer Source

This is kinda what I was looking for: Memcached::getStats();

So, I wrote:

add_memcached_server($m, $addr, $port)
    $statuses = $m->getStats();
    return isset($statuses[$addr.":".$port]);

works like a charm...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download