Skip to content

Instantly share code, notes, and snippets.

@elmariachi111
Last active September 12, 2017 15:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmariachi111/5637669a028c29e3973a to your computer and use it in GitHub Desktop.
Save elmariachi111/5637669a028c29e3973a to your computer and use it in GitHub Desktop.
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
Copy link

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
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