You are here

README.txt in Memcache API and Integration 8.2

Same filename and directory in other branches
  1. 5.2 README.txt
  2. 5 README.txt
  3. 6 README.txt
  4. 7 README.txt
## IMPORTANT NOTE ##

This file contains installation instructions for the 8.x-2.x version of the
Drupal Memcache module. Configuration differs between 8.x and 7.x versions
of the module, so be sure to follow the 7.x instructions if you are configuring
the 7.x-1.x version of this module!

## REQUIREMENTS ##

- PHP 7.0 or greater
- Availability of a memcached daemon: http://memcached.org/
- One of the two PECL memcache packages:
  - http://pecl.php.net/package/memcache (recommended)
  - http://pecl.php.net/package/memcached

For more detailed instructions on installing a memcached daemon or either of the
memcache PECL extensions, please see the documentation online at
https://www.drupal.org/node/1131458 which includes links to external
walk-throughs for various operating systems.

## INSTALLATION ##

These are the steps you need to take in order to use this software. Order
is important.

 1. Make sure you have one of the PECL memcache packages installed.
 2. Enable the memcache module.
    You need to enable the module in Drupal before you can configure it to run
    as the default backend. This is so Drupal knows where to find everything.
 2. Edit settings.php to configure the servers, clusters and bins that memcache
    is supposed to use. You do not need to set this if the only memcache backend
    is localhost on port 11211. By default the main settings will be:
      $settings['memcache']['servers'] = ['127.0.0.1:11211' => 'default'];
      $settings['memcache']['bins'] = ['default' => 'default'];
      $settings['memcache']['key_prefix'] = '';
 7. Edit settings.php to make memcache the default cache class, for example:
      $settings['cache']['default'] = 'cache.backend.memcache';
 8. If you wish to arbitrarily send cache bins to memcache, then you can do the
    following. E.g. for the cache_render bin:
      $settings['cache']['bins']['render'] = 'cache.backend.memcache';

## ADVANCED CONFIGURATION ##

### Multiple memcache backends ###

  $settings['memcache']['servers'] = [
    '127.0.0.1:11211' => 'default', // Default host and port
    '127.0.0.1:11212' => 'default', // Default host with port 11212
    '127.0.0.2:11211' => 'default', // Default port, different IP
    'server1.com:11211' => 'default', // Default port with hostname
    'unix:///path/to/socket' => 'default', 'Unix socket'
  ];

### Multiple servers, bins and clusters ###

  $settings['memcache'] = [
    'servers' = [
      'server1:port' => 'default',
      'server2:port' => 'default',
      'server3:port' => 'cluster1',
      'serverN:port' => 'clusterN',
      'unix:///path/to/socket' => 'clusterS',
    ],
    'bins' => [
      'default' => 'default',
      'bin1' => 'cluster1',
      'binN' => 'clusterN',
      'binX' => 'cluster1',
      'binS' => 'clusterS',
    ],
  ];

The bin/cluster/server model can be described as follows:

- Servers are memcached instances identified by host:port.

- Clusters are groups of servers that act as a memory pool. Each cluster can
  contain one or more servers.

- Multiple bins can be assigned to a cluster.

- The default cluster is 'default'.

- If a bin can not be found it will map to 'default'.

### Prefixing ###

If you want to have multiple Drupal installations share memcached instances,
you need to include a unique prefix for each Drupal installation in the memcache
config in settings.php:

  $settings['memcache']['key_prefix'] = 'something_unique';

### Key Hash Algorithm ###

Note: if the length of your prefix + key + bin combine to be more than 250
characters, they will be automatically hashed. Memcache only supports key
lengths up to 250 bytes. You can optionally configure the hashing algorithm
used, however sha1 was selected as the default because it performs quickly with
minimal collisions.

  $settings['memcache']['key_hash_algorithm'] = 'sha1';

Visit http://www.php.net/manual/en/function.hash-algos.php to learn more about
which hash algorithms are available.

### Memcache Distribution ###

To use this module with multiple memcached servers, it is important that you set
the hash strategy to consistent. This is controlled in the PHP extension, not the
Drupal module.

If using PECL memcache:
Edit /etc/php.d/memcache.ini (path may changed based on package/distribution) and
set the following:
memcache.hash_strategy=consistent

You need to reload apache httpd after making that change.

If using PECL memcached:
Memcached options can be controlled in settings.php. Consistent distribution is
the default in this case but could be set using:

  $setting['memcache']['options'] = [
    Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  ];

## LOCKS ##

Memcache locks can be enabled through the services.yml file.

services:
  # Replaces the default lock backend with a memcache implementation.
  lock:
    class: Drupal\Core\Lock\LockBackendInterface
    factory: memcache.lock.factory:get

## Cache Container on bootstrap (with cache tags on database) ##
By default Drupal starts the cache_container on the database, in order to
override that you can use the following code on your settings.php file. Make
sure that the $class_load->addPsr4 is pointing to the right location of
memcache (in this case modules/contrib/memcache/src)

In this mode, the database is still bootstrapped so that cache tag invalidation
can be handled. If you want to avoid database bootstrap, see the container
definition in the next section instead.

$memcache_exists = class_exists('Memcache', FALSE);
$memcached_exists = class_exists('Memcached', FALSE);
if ($memcache_exists || $memcached_exists) {
  $class_loader->addPsr4('Drupal\\memcache\\', $app_root . '/modules/contrib/memcache/src');

  // Define custom bootstrap container definition to use Memcache for cache.container.
  $settings['bootstrap_container_definition'] = [
    'parameters' => [],
    'services' => [
      'database' => [
        'class' => 'Drupal\Core\Database\Connection',
        'factory' => 'Drupal\Core\Database\Database::getConnection',
        'arguments' => ['default'],
      ],
      'settings' => [
        'class' => 'Drupal\Core\Site\Settings',
        'factory' => 'Drupal\Core\Site\Settings::getInstance',
      ],
      'memcache.settings' => [
        'class' => 'Drupal\memcache\MemcacheSettings',
        'arguments' => ['@settings'],
      ],
      'memcache.factory' => [
        'class' => 'Drupal\memcache\Driver\MemcacheDriverFactory',
        'arguments' => ['@memcache.settings'],
      ],
      'memcache.timestamp.invalidator.bin' => [
        'class' => 'Drupal\memcache\Invalidator\MemcacheTimestampInvalidator',
        # Adjust tolerance factor as appropriate when not running memcache on localhost.
        'arguments' => ['@memcache.factory', 'memcache_bin_timestamps', 0.001],
      ],
      'memcache.backend.cache.container' => [
        'class' => 'Drupal\memcache\DrupalMemcacheInterface',
        'factory' => ['@memcache.factory', 'get'],
        'arguments' => ['container'],
      ],
      'cache_tags_provider.container' => [
        'class' => 'Drupal\Core\Cache\DatabaseCacheTagsChecksum',
        'arguments' => ['@database'],
      ],
      'cache.container' => [
        'class' => 'Drupal\memcache\MemcacheBackend',
        'arguments' => ['container', '@memcache.backend.cache.container', '@cache_tags_provider.container', '@memcache.timestamp.invalidator.bin'],
      ],
    ],
  ];
}

## Cache Container on bootstrap (pure memcache) ##
By default Drupal starts the cache_container on the database, in order to
override that you can use the following code on your settings.php file.
Make sure that the $class_load->addPsr4 is pointing to the right location
of memcache (in this case modules/contrib/memcache/src)

For this mode to work correctly, you must be using the overridden cache_tags.invalidator.checksum service.
See example.services.yml for the corresponding configuration.

$memcache_exists = class_exists('Memcache', FALSE);
$memcached_exists = class_exists('Memcached', FALSE);
if ($memcache_exists || $memcached_exists) {
  $class_loader->addPsr4('Drupal\\memcache\\', 'modules/contrib/memcache/src');

  // Define custom bootstrap container definition to use Memcache for cache.container.
  $settings['bootstrap_container_definition'] = [
    'parameters' => [],
    'services' => [
      # Dependencies.
      'settings' => [
        'class' => 'Drupal\Core\Site\Settings',
        'factory' => 'Drupal\Core\Site\Settings::getInstance',
      ],
      'memcache.settings' => [
        'class' => 'Drupal\memcache\MemcacheSettings',
        'arguments' => ['@settings'],
      ],
      'memcache.factory' => [
        'class' => 'Drupal\memcache\Driver\MemcacheDriverFactory',
        'arguments' => ['@memcache.settings'],
      ],
      'memcache.timestamp.invalidator.bin' => [
        'class' => 'Drupal\memcache\Invalidator\MemcacheTimestampInvalidator',
        # Adjust tolerance factor as appropriate when not running memcache on localhost.
        'arguments' => ['@memcache.factory', 'memcache_bin_timestamps', 0.001],
      ],
      'memcache.timestamp.invalidator.tag' => [
        'class' => 'Drupal\memcache\Invalidator\MemcacheTimestampInvalidator',
        # Remember to update your main service definition in sync with this!
        # Adjust tolerance factor as appropriate when not running memcache on localhost.
        'arguments' => ['@memcache.factory', 'memcache_tag_timestamps', 0.001],
      ],
      'memcache.backend.cache.container' => [
        'class' => 'Drupal\memcache\DrupalMemcacheInterface',
        'factory' => ['@memcache.factory', 'get'],
        # Actual cache bin to use for the container cache.
        'arguments' => ['container'],
      ],
      # Define a custom cache tags invalidator for the bootstrap container.
      'cache_tags_provider.container' => [
        'class' => 'Drupal\memcache\Cache\TimestampCacheTagsChecksum',
        'arguments' => ['@memcache.timestamp.invalidator.tag'],
      ],
      'cache.container' => [
        'class' => 'Drupal\memcache\MemcacheBackend',
        'arguments' => ['container', '@memcache.backend.cache.container', '@cache_tags_provider.container', '@memcache.timestamp.invalidator.bin'],
      ],
    ],
  ];
}

## Debugging ##
By default debugging is off. To enable it add the following code in settings.php.
$setting['memcache']['debug'] = TRUE;

## TROUBLESHOOTING ##

PROBLEM:
Error:
Failed to set key: Failed to set key: cache_page-......

SOLUTION:
Upgrade your PECL library to PECL package (2.2.1) (or higher).

WARNING:
Zlib compression at the php.ini level and Memcache conflict.
See http://drupal.org/node/273824

## MEMCACHE ADMIN ##

A module offering a UI for memcache is included. It provides aggregated and
per-page statistics for memcache.

## OTHER NOTES ##

### Memcached PECL Extension Support ###

We also support the Memcached PECL extension. This extension backends
to libmemcached and allows you to use some of the newer advanced features in
memcached 1.4.

NOTE: It is important to realize that the memcache php.ini options do not impact
the memcached extension, this new extension doesn't read in options that way.
Instead, it takes options directly from Drupal. Because of this, you must
configure memcached in settings.php. Please look here for possible options:

https://secure.php.net/manual/en/memcached.constants.php

An example configuration block is below, this block also illustrates our
default options (selected through performance testing). These options will be
set unless overridden in settings.php.

  $settings['memcache']['options'] = [
    Memcached::OPT_COMPRESSION => TRUE,
    Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  ];

These are as follows:

 * Turn on compression, as this allows more data to be stored and in turn
   should result in less evictions.
 * Turn on consistent distribution, which allows you to add/remove servers
   easily

Other options you could experiment with:
 + Memcached::OPT_BINARY_PROTOCOL => TRUE,
    * This enables the Memcache binary protocol (only available in Memcached
      1.4 and later). Note that some users have reported SLOWER performance
      with this feature enabled. It should only be enabled on extremely high
      traffic networks where memcache network traffic is a bottleneck.
      Additional reading about the binary protocol:
        https://raw.githubusercontent.com/memcached/old-wiki/master/MemcacheBinaryProtocol.wiki
        Note: The information on the link above will eventually be ported to
        the new wiki under https://github.com/memcached/memcached/wiki.

 + Memcached::OPT_TCP_NODELAY => TRUE,
    * This enables the no-delay feature for connecting sockets; it's been
      reported that this can speed up the Binary protocol (see above). This
      tells the TCP stack to send packets immediately and without waiting for
      a full payload, reducing per-packet network latency (disabling "Nagling").

It's possible to enable SASL authentication as documented here:
  http://php.net/manual/en/memcached.setsaslauthdata.php
  https://code.google.com/p/memcached/wiki/SASLHowto

SASL authentication requires a memcached server with SASL support (version 1.4.3
or greater built with --enable-sasl and started with the -S flag) and the PECL
memcached client version 2.0.0 or greater also built with SASL support. Once
these requirements are satisfied you can then enable SASL support in the Drupal
memcache module by enabling the binary protocol and setting
memcache_sasl_username and memcache_sasl_password in settings.php. For example:

$settings['memcache']['sasl'] = [
  'username' => 'user',
  'password' => 'password',
];

// When using SASL, Memcached extension needs to be used
// because Memcache extension doesn't support it.
$settings['memcache']['extension'] = 'Memcached';
$settings['memcache']['options'] = [
  \Memcached::OPT_BINARY_PROTOCOL => TRUE,
];

File

README.txt
View source
  1. ## IMPORTANT NOTE ##
  2. This file contains installation instructions for the 8.x-2.x version of the
  3. Drupal Memcache module. Configuration differs between 8.x and 7.x versions
  4. of the module, so be sure to follow the 7.x instructions if you are configuring
  5. the 7.x-1.x version of this module!
  6. ## REQUIREMENTS ##
  7. - PHP 7.0 or greater
  8. - Availability of a memcached daemon: http://memcached.org/
  9. - One of the two PECL memcache packages:
  10. - http://pecl.php.net/package/memcache (recommended)
  11. - http://pecl.php.net/package/memcached
  12. For more detailed instructions on installing a memcached daemon or either of the
  13. memcache PECL extensions, please see the documentation online at
  14. https://www.drupal.org/node/1131458 which includes links to external
  15. walk-throughs for various operating systems.
  16. ## INSTALLATION ##
  17. These are the steps you need to take in order to use this software. Order
  18. is important.
  19. 1. Make sure you have one of the PECL memcache packages installed.
  20. 2. Enable the memcache module.
  21. You need to enable the module in Drupal before you can configure it to run
  22. as the default backend. This is so Drupal knows where to find everything.
  23. 2. Edit settings.php to configure the servers, clusters and bins that memcache
  24. is supposed to use. You do not need to set this if the only memcache backend
  25. is localhost on port 11211. By default the main settings will be:
  26. $settings['memcache']['servers'] = ['127.0.0.1:11211' => 'default'];
  27. $settings['memcache']['bins'] = ['default' => 'default'];
  28. $settings['memcache']['key_prefix'] = '';
  29. 7. Edit settings.php to make memcache the default cache class, for example:
  30. $settings['cache']['default'] = 'cache.backend.memcache';
  31. 8. If you wish to arbitrarily send cache bins to memcache, then you can do the
  32. following. E.g. for the cache_render bin:
  33. $settings['cache']['bins']['render'] = 'cache.backend.memcache';
  34. ## ADVANCED CONFIGURATION ##
  35. ### Multiple memcache backends ###
  36. $settings['memcache']['servers'] = [
  37. '127.0.0.1:11211' => 'default', // Default host and port
  38. '127.0.0.1:11212' => 'default', // Default host with port 11212
  39. '127.0.0.2:11211' => 'default', // Default port, different IP
  40. 'server1.com:11211' => 'default', // Default port with hostname
  41. 'unix:///path/to/socket' => 'default', 'Unix socket'
  42. ];
  43. ### Multiple servers, bins and clusters ###
  44. $settings['memcache'] = [
  45. 'servers' = [
  46. 'server1:port' => 'default',
  47. 'server2:port' => 'default',
  48. 'server3:port' => 'cluster1',
  49. 'serverN:port' => 'clusterN',
  50. 'unix:///path/to/socket' => 'clusterS',
  51. ],
  52. 'bins' => [
  53. 'default' => 'default',
  54. 'bin1' => 'cluster1',
  55. 'binN' => 'clusterN',
  56. 'binX' => 'cluster1',
  57. 'binS' => 'clusterS',
  58. ],
  59. ];
  60. The bin/cluster/server model can be described as follows:
  61. - Servers are memcached instances identified by host:port.
  62. - Clusters are groups of servers that act as a memory pool. Each cluster can
  63. contain one or more servers.
  64. - Multiple bins can be assigned to a cluster.
  65. - The default cluster is 'default'.
  66. - If a bin can not be found it will map to 'default'.
  67. ### Prefixing ###
  68. If you want to have multiple Drupal installations share memcached instances,
  69. you need to include a unique prefix for each Drupal installation in the memcache
  70. config in settings.php:
  71. $settings['memcache']['key_prefix'] = 'something_unique';
  72. ### Key Hash Algorithm ###
  73. Note: if the length of your prefix + key + bin combine to be more than 250
  74. characters, they will be automatically hashed. Memcache only supports key
  75. lengths up to 250 bytes. You can optionally configure the hashing algorithm
  76. used, however sha1 was selected as the default because it performs quickly with
  77. minimal collisions.
  78. $settings['memcache']['key_hash_algorithm'] = 'sha1';
  79. Visit http://www.php.net/manual/en/function.hash-algos.php to learn more about
  80. which hash algorithms are available.
  81. ### Memcache Distribution ###
  82. To use this module with multiple memcached servers, it is important that you set
  83. the hash strategy to consistent. This is controlled in the PHP extension, not the
  84. Drupal module.
  85. If using PECL memcache:
  86. Edit /etc/php.d/memcache.ini (path may changed based on package/distribution) and
  87. set the following:
  88. memcache.hash_strategy=consistent
  89. You need to reload apache httpd after making that change.
  90. If using PECL memcached:
  91. Memcached options can be controlled in settings.php. Consistent distribution is
  92. the default in this case but could be set using:
  93. $setting['memcache']['options'] = [
  94. Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  95. ];
  96. ## LOCKS ##
  97. Memcache locks can be enabled through the services.yml file.
  98. services:
  99. # Replaces the default lock backend with a memcache implementation.
  100. lock:
  101. class: Drupal\Core\Lock\LockBackendInterface
  102. factory: memcache.lock.factory:get
  103. ## Cache Container on bootstrap (with cache tags on database) ##
  104. By default Drupal starts the cache_container on the database, in order to
  105. override that you can use the following code on your settings.php file. Make
  106. sure that the $class_load->addPsr4 is pointing to the right location of
  107. memcache (in this case modules/contrib/memcache/src)
  108. In this mode, the database is still bootstrapped so that cache tag invalidation
  109. can be handled. If you want to avoid database bootstrap, see the container
  110. definition in the next section instead.
  111. $memcache_exists = class_exists('Memcache', FALSE);
  112. $memcached_exists = class_exists('Memcached', FALSE);
  113. if ($memcache_exists || $memcached_exists) {
  114. $class_loader->addPsr4('Drupal\\memcache\\', $app_root . '/modules/contrib/memcache/src');
  115. // Define custom bootstrap container definition to use Memcache for cache.container.
  116. $settings['bootstrap_container_definition'] = [
  117. 'parameters' => [],
  118. 'services' => [
  119. 'database' => [
  120. 'class' => 'Drupal\Core\Database\Connection',
  121. 'factory' => 'Drupal\Core\Database\Database::getConnection',
  122. 'arguments' => ['default'],
  123. ],
  124. 'settings' => [
  125. 'class' => 'Drupal\Core\Site\Settings',
  126. 'factory' => 'Drupal\Core\Site\Settings::getInstance',
  127. ],
  128. 'memcache.settings' => [
  129. 'class' => 'Drupal\memcache\MemcacheSettings',
  130. 'arguments' => ['@settings'],
  131. ],
  132. 'memcache.factory' => [
  133. 'class' => 'Drupal\memcache\Driver\MemcacheDriverFactory',
  134. 'arguments' => ['@memcache.settings'],
  135. ],
  136. 'memcache.timestamp.invalidator.bin' => [
  137. 'class' => 'Drupal\memcache\Invalidator\MemcacheTimestampInvalidator',
  138. # Adjust tolerance factor as appropriate when not running memcache on localhost.
  139. 'arguments' => ['@memcache.factory', 'memcache_bin_timestamps', 0.001],
  140. ],
  141. 'memcache.backend.cache.container' => [
  142. 'class' => 'Drupal\memcache\DrupalMemcacheInterface',
  143. 'factory' => ['@memcache.factory', 'get'],
  144. 'arguments' => ['container'],
  145. ],
  146. 'cache_tags_provider.container' => [
  147. 'class' => 'Drupal\Core\Cache\DatabaseCacheTagsChecksum',
  148. 'arguments' => ['@database'],
  149. ],
  150. 'cache.container' => [
  151. 'class' => 'Drupal\memcache\MemcacheBackend',
  152. 'arguments' => ['container', '@memcache.backend.cache.container', '@cache_tags_provider.container', '@memcache.timestamp.invalidator.bin'],
  153. ],
  154. ],
  155. ];
  156. }
  157. ## Cache Container on bootstrap (pure memcache) ##
  158. By default Drupal starts the cache_container on the database, in order to
  159. override that you can use the following code on your settings.php file.
  160. Make sure that the $class_load->addPsr4 is pointing to the right location
  161. of memcache (in this case modules/contrib/memcache/src)
  162. For this mode to work correctly, you must be using the overridden cache_tags.invalidator.checksum service.
  163. See example.services.yml for the corresponding configuration.
  164. $memcache_exists = class_exists('Memcache', FALSE);
  165. $memcached_exists = class_exists('Memcached', FALSE);
  166. if ($memcache_exists || $memcached_exists) {
  167. $class_loader->addPsr4('Drupal\\memcache\\', 'modules/contrib/memcache/src');
  168. // Define custom bootstrap container definition to use Memcache for cache.container.
  169. $settings['bootstrap_container_definition'] = [
  170. 'parameters' => [],
  171. 'services' => [
  172. # Dependencies.
  173. 'settings' => [
  174. 'class' => 'Drupal\Core\Site\Settings',
  175. 'factory' => 'Drupal\Core\Site\Settings::getInstance',
  176. ],
  177. 'memcache.settings' => [
  178. 'class' => 'Drupal\memcache\MemcacheSettings',
  179. 'arguments' => ['@settings'],
  180. ],
  181. 'memcache.factory' => [
  182. 'class' => 'Drupal\memcache\Driver\MemcacheDriverFactory',
  183. 'arguments' => ['@memcache.settings'],
  184. ],
  185. 'memcache.timestamp.invalidator.bin' => [
  186. 'class' => 'Drupal\memcache\Invalidator\MemcacheTimestampInvalidator',
  187. # Adjust tolerance factor as appropriate when not running memcache on localhost.
  188. 'arguments' => ['@memcache.factory', 'memcache_bin_timestamps', 0.001],
  189. ],
  190. 'memcache.timestamp.invalidator.tag' => [
  191. 'class' => 'Drupal\memcache\Invalidator\MemcacheTimestampInvalidator',
  192. # Remember to update your main service definition in sync with this!
  193. # Adjust tolerance factor as appropriate when not running memcache on localhost.
  194. 'arguments' => ['@memcache.factory', 'memcache_tag_timestamps', 0.001],
  195. ],
  196. 'memcache.backend.cache.container' => [
  197. 'class' => 'Drupal\memcache\DrupalMemcacheInterface',
  198. 'factory' => ['@memcache.factory', 'get'],
  199. # Actual cache bin to use for the container cache.
  200. 'arguments' => ['container'],
  201. ],
  202. # Define a custom cache tags invalidator for the bootstrap container.
  203. 'cache_tags_provider.container' => [
  204. 'class' => 'Drupal\memcache\Cache\TimestampCacheTagsChecksum',
  205. 'arguments' => ['@memcache.timestamp.invalidator.tag'],
  206. ],
  207. 'cache.container' => [
  208. 'class' => 'Drupal\memcache\MemcacheBackend',
  209. 'arguments' => ['container', '@memcache.backend.cache.container', '@cache_tags_provider.container', '@memcache.timestamp.invalidator.bin'],
  210. ],
  211. ],
  212. ];
  213. }
  214. ## Debugging ##
  215. By default debugging is off. To enable it add the following code in settings.php.
  216. $setting['memcache']['debug'] = TRUE;
  217. ## TROUBLESHOOTING ##
  218. PROBLEM:
  219. Error:
  220. Failed to set key: Failed to set key: cache_page-......
  221. SOLUTION:
  222. Upgrade your PECL library to PECL package (2.2.1) (or higher).
  223. WARNING:
  224. Zlib compression at the php.ini level and Memcache conflict.
  225. See http://drupal.org/node/273824
  226. ## MEMCACHE ADMIN ##
  227. A module offering a UI for memcache is included. It provides aggregated and
  228. per-page statistics for memcache.
  229. ## OTHER NOTES ##
  230. ### Memcached PECL Extension Support ###
  231. We also support the Memcached PECL extension. This extension backends
  232. to libmemcached and allows you to use some of the newer advanced features in
  233. memcached 1.4.
  234. NOTE: It is important to realize that the memcache php.ini options do not impact
  235. the memcached extension, this new extension doesn't read in options that way.
  236. Instead, it takes options directly from Drupal. Because of this, you must
  237. configure memcached in settings.php. Please look here for possible options:
  238. https://secure.php.net/manual/en/memcached.constants.php
  239. An example configuration block is below, this block also illustrates our
  240. default options (selected through performance testing). These options will be
  241. set unless overridden in settings.php.
  242. $settings['memcache']['options'] = [
  243. Memcached::OPT_COMPRESSION => TRUE,
  244. Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  245. ];
  246. These are as follows:
  247. * Turn on compression, as this allows more data to be stored and in turn
  248. should result in less evictions.
  249. * Turn on consistent distribution, which allows you to add/remove servers
  250. easily
  251. Other options you could experiment with:
  252. + Memcached::OPT_BINARY_PROTOCOL => TRUE,
  253. * This enables the Memcache binary protocol (only available in Memcached
  254. 1.4 and later). Note that some users have reported SLOWER performance
  255. with this feature enabled. It should only be enabled on extremely high
  256. traffic networks where memcache network traffic is a bottleneck.
  257. Additional reading about the binary protocol:
  258. https://raw.githubusercontent.com/memcached/old-wiki/master/MemcacheBinaryProtocol.wiki
  259. Note: The information on the link above will eventually be ported to
  260. the new wiki under https://github.com/memcached/memcached/wiki.
  261. + Memcached::OPT_TCP_NODELAY => TRUE,
  262. * This enables the no-delay feature for connecting sockets; it's been
  263. reported that this can speed up the Binary protocol (see above). This
  264. tells the TCP stack to send packets immediately and without waiting for
  265. a full payload, reducing per-packet network latency (disabling "Nagling").
  266. It's possible to enable SASL authentication as documented here:
  267. http://php.net/manual/en/memcached.setsaslauthdata.php
  268. https://code.google.com/p/memcached/wiki/SASLHowto
  269. SASL authentication requires a memcached server with SASL support (version 1.4.3
  270. or greater built with --enable-sasl and started with the -S flag) and the PECL
  271. memcached client version 2.0.0 or greater also built with SASL support. Once
  272. these requirements are satisfied you can then enable SASL support in the Drupal
  273. memcache module by enabling the binary protocol and setting
  274. memcache_sasl_username and memcache_sasl_password in settings.php. For example:
  275. $settings['memcache']['sasl'] = [
  276. 'username' => 'user',
  277. 'password' => 'password',
  278. ];
  279. // When using SASL, Memcached extension needs to be used
  280. // because Memcache extension doesn't support it.
  281. $settings['memcache']['extension'] = 'Memcached';
  282. $settings['memcache']['options'] = [
  283. \Memcached::OPT_BINARY_PROTOCOL => TRUE,
  284. ];