Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Symfony2 Memcached settings for persistent connections
<?php
namespace Acme\CoreBundle\Classes\Cache;
class AcmeMemcached extends \Memcached {
function __construct($persistent_id)
{
parent::__construct($persistent_id);
}
/**
* prevent adding of new servers. We're persistent!
*/
public function addServers(array $servers)
{
if (0 == count($this->getServerList())) {
parent::addServers($servers);
}
}
}
services:
memcache.servers:
class: Acme\CoreBundle\Classes\Cache\AcmeMemcached
arguments: [ "acme_mc" ] #persistent id
calls:
- [ addServers, [ [ ["10.0.0.1",11211, 50 ], ["10.0.0.2",11211,25], ["10.0.0.3",11211,25] ] ] ]
@adamquaile

This comment has been minimized.

Copy link

adamquaile commented Jul 8, 2015

I know this is old, but for anyone stumbling across this. Just be aware there is also a singular addServer method you may want to override too. Otherwise it's still possible to end up with multiple open connections.

@benr77

This comment has been minimized.

Copy link

benr77 commented Jul 29, 2015

I've added the method for addServer as well - see my Gist based on this one. https://gist.github.com/benr77/258e42642b4632d5a826#file-memcachedwrapper-php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.