This page contains configurations which are specific to PECL Memcached extension.

Change extension options

First, check out the list of possible options here. You might want to play with those settings to get the best performance settings.

Example of configuration array you will find below. It contains the default options which Memcache Storage uses to initialize memcached connection with PECL Memcached (although they're overridable):

Drupal 7:

$conf['memcache_options'] = array(
  Memcached::OPT_COMPRESSION => FALSE,
  Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
);

Drupal 8:

$settings['memcache_storage']['memcached_options'] = [
  \Memcached::OPT_COMPRESSION => FALSE,
  \Memcached::OPT_DISTRIBUTION => \Memcached::DISTRIBUTION_CONSISTENT,
];

If you use memcached daemon 1.4 or above, then you can enable binary protocol support, which is more advanced and (in theory) faster by adding the following option:

Drupal 7:

$conf['memcache_options'] = array(
  Memcached::OPT_BINARY_PROTOCOL => TRUE,
);

Drupal 8:

$settings['memcache_storage']['memcached_options'] = [
  \Memcached::OPT_BINARY_PROTOCOL => FALSE,
];

Note that you will also have to compile the memcached daemon lib with binary protocol enabled, see documentation for more info.

If you experienced slower performance when using the binary protocol, consider enabling tcp no-delay mode as well:

Drupal 7:

$conf['memcache_options'] = array(
  Memcached::OPT_TCP_NODELAY => TRUE,
  Memcached::OPT_BINARY_PROTOCOL => TRUE,
);

Drupal 8:

$settings['memcache_storage']['memcached_options'] = [
  \Memcached::OPT_TCP_NODELAY => TRUE,
  \Memcached::OPT_BINARY_PROTOCOL => TRUE,
];

SASL Authentication

Memcached supports authentication via SASL protocol. This can be used to effectively limit which users on a system can access memcached,
as well as to strengthen it's security (not cool if user A can read data from user B...). Particularly useful on a shared hosting environment or on a open system.

Note that:

  • SASL works only when binary protocol is enabled, so you need to configure your memcached daemon to work with binary protocol (-B binary).
  • This method is only available when the Memcached PECL extension is build with SASL support.

How to enable SASL in Memcached daemon:

  • Add the flag "-S" in /etc/memcached.conf (Debian).
  • Create an user for the login being used for memcached under php: "sudo saslpasswd2 -a memcached -c someuser" and type a password.

How to enable SASL in Memcached PECL extension:

  • Add the option "memcached.use_sasl = 1" in /etc/php5/mods-available/memcached.ini or on your site's php.ini;

Add following configs to settings.php:

Drupal 7:

$conf['memcache_sasl_auth'] = array(
  'user' => 'username',
  'password' => 'userpassword',
);

Drupal 8:

$settings['memcache_storage']['sasl_auth'] = [
  'user' => 'username',
  'password' => 'userpassword',
];