failover with pecl-memcached

24 views
Skip to first unread message

pipapo

unread,
Mar 11, 2010, 10:02:12 AM3/11/10
to memcached
Hello! I am using php -> pecl-memcached_2.0.0 -> libmemcached_0.37 ->
2* memcached_1.4.4

What I am trying to do is some sort of failover in case one memcached
fails. My testing code is below.

What I have expected to see is to have the requests going to the other
server if one drops out. However, when I start this script with both
servers up, the request are going to the first one. When I kill that
memcached-server, it keeps on trying to use the first server, and
never uses the second.

What do I need to do to get one server out of the pool if it is gone?

Thanks a lot!

<?php
$m = new Memcached();

$m->addServer('192.168.0.248', 11211);
$m->addServer('192.168.0.249', 11211);

$m-
>setOption(Memcached::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT);
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$m->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT, 5);

while(1){
$m->set('1234','ojcojo');
$lala=$m->get('1234');
echo("$lala \n");
sleep(1);
}

Reply all
Reply to author
Forward
0 new messages