Hi, guys. I am using PECL memcached and my memcache server is a remote server. I can configure PHP for a PECL memcached without SASL. But I don't know how to use this with SASL. Can someone give me a tip? I check the internet, but the articles are out of date. Many thanks!

Comments

Jeremy’s picture

I don't recommend running Memcached on a remote network. Memcached is typically used as a caching layer with Drupal, and this needs to be fast. Putting memcached on a remote network will introduce network latency, and could result in your caching layer slowing things down rather than speeding them up.

Further, it looks like 1) you'll have to use the PECL memcached (note the 'd' at the end) extension which is not recommended, 2) you'll have to enable the Binary protocol on the client, 3) you'll have to launch the memcached binary with the -S flag (see https://code.google.com/p/memcached/wiki/SASLHowto ), and 4) the memcache Drupal module likely will have to be patched to properly authenticate with each connection (see http://php.net/manual/en/memcached.setsaslauthdata.php ).

Leaving this as a feature request, as #4 will require a patch. I have no intention of working on this myself, but patches are welcome.

elantion’s picture

Yes, I have to do those requests as you said. And now, I can make it work now.
At the function "dmemcache_connect" in dmemcache.inc, I just add some settings in this function and it work.
Like this:
$rc = $memcache->setOption(Memcached::OPT_COMPRESSION, false);
$rc = $memcache->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$rc = $memcache->addServer('remote.server.com', 11211);
$rc = $memcache->setSaslAuthData('username', 'password');

I don't kown why this can work , I just did.

Jeremy’s picture

The first three options you can actually set in settings.php. You'd do something like this (better explained in README.txt):

$conf['memcache_options'] = array(
  Memcached::OPT_COMPRESSION => FALSE,
  Memcached::OPT_BINARY_PROTOCOL => TRUE,
);
$conf['memcache_servers'] = array('remote.server.com:11211' => 'default');

It's only the final option (->setSaslAuthData) that requires a patch.

I'm glad to hear it's working for you. Leaving open as a feature request so that this can be fully configured from settings.php and without patching dmemcache.inc.

  • Jeremy committed 773d3e8 on 7.x-1.x
    Issue #2382225 by Jeremy: Support Memcached SASL
    
Jeremy’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Active » Patch (to be ported)

I've added SASL support, documented in the README:
http://cgit.drupalcode.org/memcache/commit/?id=773d3e8

Tagging to be ported to 6.x-1.x.

Jeremy’s picture

Status: Patch (to be ported) » Fixed

  • Jeremy committed 997f1f1 on 6.x-1.x
    Issue #2382225: document using SASL with memcache
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.