Skip to content

Instantly share code, notes, and snippets.

@avargas
Created June 2, 2011 14:54
Show Gist options
  • Save avargas/1004594 to your computer and use it in GitHub Desktop.
Save avargas/1004594 to your computer and use it in GitHub Desktop.
PHP Memcached failover
<?php
$mem = new Memcached("pool");
$mem->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$mem->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
$mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$mem->setOption(Memcached::OPT_NO_BLOCK, true);
$mem->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT, 1);
$mem->setOption(Memcached::OPT_RETRY_TIMEOUT, 30);
$mem->setOption(29, 2);
if (!count($mem->getServerList())) {
$mem->addServers(array(
array('127.0.0.1', 10001),
array('127.0.0.1', 10002),
array('127.0.0.1', 10003),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment