README.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. ## IMPORTANT NOTE ##
  2. This file contains installation instructions for the 7.x-1.x version of the
  3. Drupal Memcache module. Configuration differs between 7.x and 6.x versions
  4. of the module, so be sure to follow the 6.x instructions if you are configuring
  5. the 6.x-1.x version of this module!
  6. ## REQUIREMENTS ##
  7. - PHP 5.1 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 (latest versions require PHP 5.2 or
  12. greater)
  13. ## INSTALLATION ##
  14. These are the steps you need to take in order to use this software. Order
  15. is important.
  16. 1. Install the memcached binaries on your server and start the memcached
  17. service. Follow best practices for securing the service; for example,
  18. lock it down so only your web servers can make connections. Find community
  19. maintained documentation with a number of walk-throughs for various
  20. operating systems at https://www.drupal.org/node/1131458.
  21. 2. Install your chosen PECL memcache extension -- this is the memcache client
  22. library which will be used by the Drupal memcache module to interact with
  23. the memcached server(s). Generally PECL memcache (3.0.6+) is recommended,
  24. but PECL memcached (2.0.1+) also works well for some people. There are
  25. known issues with older versions. Refer to the community maintained
  26. documentation referenced above for more information.
  27. 3. Put your site into offline mode.
  28. 4. Download and install the memcache module.
  29. 5. If you have previously been running the memcache module, run update.php.
  30. 6. Optionally edit settings.php to configure the servers, clusters and bins
  31. for memcache to use. If you skip this step the Drupal module will attempt to
  32. talk to the memcache server on port 11211 on the local host, storing all
  33. data in a single bin. This is sufficient for most smaller, single-server
  34. installations.
  35. 7. Edit settings.php to make memcache the default cache class, for example:
  36. $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
  37. $conf['cache_default_class'] = 'MemCacheDrupal';
  38. The cache_backends path needs to be adjusted based on where you installed
  39. the module.
  40. 8. Make sure the following line also exists, to ensure that the special
  41. cache_form bin is assigned to non-volatile storage:
  42. $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
  43. 9. Optionally also add the following two lines to tell Drupal not to bootstrap
  44. the database when serving cached pages to anonymous visitors:
  45. $conf['page_cache_without_database'] = TRUE;
  46. $conf['page_cache_invoke_hooks'] = FALSE;
  47. If setting page_cache_without_database to TRUE, you also have to set
  48. page_cache_invoke_hooks to FALSE or you'll see an error like "Fatal error:
  49. Call to undefined function module_list()".
  50. 10. Bring your site back online.
  51. ## DRUSH ##
  52. Enable the memcache module at admin/modules or with 'drush en memcache', then
  53. rebuild the drush cache by running 'drush cc drush'. This will enable the
  54. following drush commands:
  55. memcache-flush (mcf) Flush all Memcached objects in a bin.
  56. memcache-stats (mcs) Retrieve statistics from Memcached.
  57. For more information about each command, use 'drush help'. For example:
  58. drush help mcf
  59. Or:
  60. drush help mcs
  61. ## ADVANCED CONFIGURATION ##
  62. This module is capable of working with one memcached instance or with multiple
  63. memcached instances run across one or more servers. The default is to use one
  64. server accessible on localhost port 11211. If that meets your needs, then the
  65. configuration settings outlined above are sufficient for the module to work.
  66. If you want to use multiple memcached instances, or if you are connecting to a
  67. memcached instance located on a remote machine, further configuration is
  68. required.
  69. The available memcached servers are specified in $conf in settings.php. If you
  70. do not specify any servers, memcache.inc assumes that you have a memcached
  71. instance running on localhost:11211. If this is true, and it is the only
  72. memcached instance you wish to use, no further configuration is required.
  73. If you have more than one memcached instance running, you need to add two arrays
  74. to $conf; memcache_servers and memcache_bins. The arrays follow this pattern:
  75. 'memcache_servers' => array(
  76. server1:port => cluster1,
  77. server2:port => cluster2,
  78. serverN:port => clusterN,
  79. 'unix:///path/to/socket' => clusterS
  80. )
  81. 'memcache_bins' => array(
  82. bin1 => cluster1,
  83. bin2 => cluster2,
  84. binN => clusterN,
  85. binS => clusterS
  86. )
  87. You can optionally assign a weight to each server, favoring one server more than
  88. another. For example, to make it 10 times more likely to store an item on
  89. server1 versus server2:
  90. 'memcache_servers' => array(
  91. server1:port => array('cluster' => cluster1, 'weight' => 10),
  92. server2:port => array('cluster' => cluster2, 'weight' => 1'),
  93. )
  94. The bin/cluster/server model can be described as follows:
  95. - Servers are memcached instances identified by host:port.
  96. - Clusters are groups of servers that act as a memory pool. Each cluster can
  97. contain one or more servers.
  98. - Bins are groups of data that get cached together and map 1:1 to the $table
  99. parameter of cache_set(). Examples from Drupal core are cache_filter and
  100. cache_menu. The default is 'cache'.
  101. - Multiple bins can be assigned to a cluster.
  102. - The default cluster is 'default'.
  103. ## LOCKING ##
  104. The memcache-lock.inc file included with this module can be used as a drop-in
  105. replacement for the database-mediated locking mechanism provided by Drupal
  106. core. To enable, define the following in your settings.php:
  107. $conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
  108. Locks are written in the 'semaphore' table, which will map to the 'default'
  109. memcache cluster unless you explicitly configure a 'semaphore' cluster.
  110. ## STAMPEDE PROTECTION ##
  111. Memcache includes stampede protection for rebuilding expired and invalid cache
  112. items. To enable stampede protection, define the following in settings.php:
  113. $conf['memcache_stampede_protection'] = TRUE;
  114. To avoid lock stampedes, it is important that you enable the memcache lock
  115. implementation when enabling stampede protection -- enabling stampede protection
  116. without enabling the Memcache lock implementation can cause worse performance and
  117. can result in dropped locks due to key-length truncation.
  118. Memcache stampede protection is primarily designed to benefit the following
  119. caching pattern: a miss on a cache_get() for a specific cid is immediately
  120. followed by a cache_set() for that cid. Of course, this is not the only caching
  121. pattern used in Drupal, so stampede protection can be selectively disabled for
  122. optimal performance. For example, a cache miss in Drupal core's
  123. module_implements() won't execute a cache_set until drupal_page_footer()
  124. calls module_implements_write_cache() which can occur much later in page
  125. generation. To avoid long hanging locks, stampede protection should be
  126. disabled for these delayed caching patterns.
  127. Memcache stampede protection can be disabled for entire bins, specific cid's in
  128. specific bins, or cid's starting with a specific prefix in specific bins. For
  129. example:
  130. $conf['memcache_stampede_protection_ignore'] = array(
  131. // Ignore some cids in 'cache_bootstrap'.
  132. 'cache_bootstrap' => array(
  133. 'module_implements',
  134. 'variables',
  135. 'lookup_cache',
  136. 'schema:runtime:*',
  137. 'theme_registry:runtime:*',
  138. '_drupal_file_scan_cache',
  139. ),
  140. // Ignore all cids in the 'cache' bin starting with 'i18n:string:'
  141. 'cache' => array(
  142. 'i18n:string:*',
  143. ),
  144. // Disable stampede protection for the entire 'cache_path' and 'cache_rules'
  145. // bins.
  146. 'cache_path',
  147. 'cache_rules',
  148. );
  149. Only change the following stampede protection tunables if you're sure you know
  150. what you're doing, which requires first reading the memcache.inc code.
  151. The value passed to lock_acquire, defaults to '15':
  152. $conf['memcache_stampede_semaphore'] = 15;
  153. The value passed to lock_wait, defaults to 5:
  154. $conf['memcache_stampede_wait_time'] = 5;
  155. The maximum number of calls to lock_wait() due to stampede protection during a
  156. single request, defaults to 3:
  157. $conf['memcache_stampede_wait_limit'] = 3;
  158. When adjusting these variables, be aware that:
  159. - there is unlikely to be a good use case for setting wait_time higher
  160. than stampede_semaphore;
  161. - wait_time * wait_limit is designed to default to a number less than
  162. standard web server timeouts (i.e. 15 seconds vs. apache's default of
  163. 30 seconds).
  164. ## CACHE LIFETIME ##
  165. Memcache respects Drupal core's minimum cache lifetime configuration. This
  166. setting affects all cached items, not just pages. In some cases, it may
  167. be desirable to cache different types of items for different amounts of time.
  168. You can override the minimum cache lifetime on a per-bin basis in settings.php.
  169. For example:
  170. // Cache pages for 60 seconds.
  171. $conf['cache_lifetime_cache_page'] = 60;
  172. // Cache menus for 10 minutes.
  173. $conf['cache_lifetime_menu'] = 600;
  174. ## CACHE HEADER ##
  175. Drupal core indicates whether or not a page was served out of the cache by
  176. setting the 'X-Drupal-Cache' response header with a value of HIT or MISS. If
  177. you'd like to confirm whether pages are actually being retreived from Memcache
  178. and not another backend, you can enable the following option:
  179. $conf['memcache_pagecache_header'] = TRUE;
  180. When enabled, the Memcache module will add its own 'Drupal-PageCache-Memcache'
  181. header. When cached pages are served out of the cache the header will include an
  182. 'age=' value indicating how many seconds ago the page was stored in the cache.
  183. ## PERSISTENT CONNECTIONS ##
  184. As of 7.x-1.6, the memcache module uses peristent connections by default. If
  185. this causes you problems you can disable persistent connections by adding the
  186. following to your settings.php:
  187. $conf['memcache_persistent'] = FALSE;
  188. ## EXAMPLES ##
  189. Example 1:
  190. First, the most basic configuration which consists of one memcached instance
  191. running on localhost port 11211 and all caches except for cache_form being
  192. stored in memcache. We also enable stampede protection, and the memcache
  193. locking mechanism. Finally, we tell Drupal to not bootstrap the database when
  194. serving cached pages to anonymous visitors.
  195. $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
  196. $conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
  197. $conf['memcache_stampede_protection'] = TRUE;
  198. $conf['cache_default_class'] = 'MemCacheDrupal';
  199. // The 'cache_form' bin must be assigned to non-volatile storage.
  200. $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
  201. // Don't bootstrap the database when serving pages from the cache.
  202. $conf['page_cache_without_database'] = TRUE;
  203. $conf['page_cache_invoke_hooks'] = FALSE;
  204. Note that no servers or bins are defined. The default server and bin
  205. configuration which is used in this case is equivalant to setting:
  206. $conf['memcache_servers'] = array('localhost:11211' => 'default');
  207. Example 2:
  208. In this example we define three memcached instances, two accessed over the
  209. network, and one on a Unix socket -- please note this is only an illustration of
  210. what is possible, and is not a recommended configuration as it's highly unlikely
  211. you'd want to configure memcache to use both sockets and network addresses like
  212. this, instead you'd consistently use one or the other.
  213. The instance on port 11211 belongs to the 'default' cluster where everything
  214. gets cached that isn't otherwise defined. (We refer to it as a "cluster", but in
  215. this example our "clusters" involve only one instance.) The instance on port
  216. 11212 belongs to the 'pages' cluster, with the 'cache_page' table mapped to
  217. it -- so the Drupal page cache is stored in this cluster. Finally, the instance
  218. listening on a socket is part of the 'blocks' cluster, with the 'cache_block'
  219. table mapped to it -- so the Drupal block cache is stored here. Note that
  220. sockets do not have ports.
  221. $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
  222. $conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
  223. $conf['memcache_stampede_protection'] = TRUE;
  224. $conf['cache_default_class'] = 'MemCacheDrupal';
  225. // The 'cache_form' bin must be assigned no non-volatile storage.
  226. $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
  227. // Don't bootstrap the database when serving pages from the cache.
  228. $conf['page_cache_without_database'] = TRUE;
  229. $conf['page_cache_invoke_hooks'] = FALSE;
  230. // Important to define a default cluster in both the servers
  231. // and in the bins. This links them together.
  232. $conf['memcache_servers'] = array('10.1.1.1:11211' => 'default',
  233. '10.1.1.1:11212' => 'pages',
  234. 'unix:///path/to/socket' => 'blocks');
  235. $conf['memcache_bins'] = array('cache' => 'default',
  236. 'cache_page' => 'pages',
  237. 'cache_block' => 'blocks');
  238. Example 3:
  239. Here is an example configuration that has two clusters, 'default' and
  240. 'cluster2'. Five memcached instances running on four different servers are
  241. divided up between the two clusters. The 'cache_filter' and 'cache_menu' bins
  242. go to 'cluster2'. All other bins go to 'default'.
  243. $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
  244. $conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
  245. $conf['memcache_stampede_protection'] = TRUE;
  246. $conf['cache_default_class'] = 'MemCacheDrupal';
  247. // The 'cache_form' bin must be assigned no non-volatile storage.
  248. $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
  249. // Don't bootstrap the database when serving pages from the cache.
  250. $conf['page_cache_without_database'] = TRUE;
  251. $conf['page_cache_invoke_hooks'] = FALSE;
  252. $conf['memcache_servers'] = array('10.1.1.6:11211' => 'default',
  253. '10.1.1.6:11212' => 'default',
  254. '10.1.1.7:11211' => 'default',
  255. '10.1.1.8:11211' => 'cluster2',
  256. '10.1.1.9:11211' => 'cluster2');
  257. $conf['memcache_bins'] = array('cache' => 'default',
  258. 'cache_filter' => 'cluster2',
  259. 'cache_menu' => 'cluster2');
  260. );
  261. ## PREFIXING ##
  262. If you want to have multiple Drupal installations share memcached instances,
  263. you need to include a unique prefix for each Drupal installation in the $conf
  264. array of settings.php. This can be a single string prefix, or a keyed array of
  265. bin => prefix pairs:
  266. $conf['memcache_key_prefix'] = 'something_unique';
  267. Using a per-bin prefix:
  268. $conf['memcache_key_prefix'] = array(
  269. 'default' => 'something_unique',
  270. 'cache_page' => 'something_else_unique'
  271. );
  272. In the above example, the 'something_unique' prefix will be used for all bins
  273. except for the 'cache_page' bin which will use the 'something_else_unique'
  274. prefix. Note that if using a keyed array for specifying prefix, you must specify
  275. the 'default' prefix.
  276. It is also possible to specify multiple prefixes per bin. Only the first prefix
  277. will be used when setting/getting cache items, but all prefixes will be cleared
  278. when deleting cache items. This provides support for more complicated
  279. configurations such as a live instance and an administrative instance each with
  280. their own prefixes and therefore their own unique caches. Any time a cache item
  281. is deleted on either instance, it gets flushed on both -- thus, should an admin
  282. do something that flushes the page cache, it will appropriately get flushed on
  283. both instances. (For more discussion see the issue where support was added,
  284. https://www.drupal.org/node/1084448.) This feature is enabled when you configure
  285. prefixes as arrays within arrays. For example:
  286. // Live instance.
  287. $conf['memcache_key_prefix'] = array(
  288. 'default' => array(
  289. 'live_unique', // live cache prefix
  290. 'admin_unique', // admin cache prefix
  291. ),
  292. );
  293. The above would be the configuration of your live instance. Then, on your
  294. administrative instance you would flip the keys:
  295. // Administrative instance.
  296. $conf['memcache_key_prefix'] = array(
  297. 'default' => array(
  298. 'admin_unique', // admin cache prefix
  299. 'live_unique', // live cache prefix
  300. ),
  301. );
  302. ## EXPERIMENTAL - ALTERNATIVE SERIALIZE ##
  303. This is a new experimental feature added to the memcache module in version
  304. 7.x-1.6 and should be tested carefully before utilizing in production.
  305. To optimize how data is serialized before it is written to memcache, you can
  306. enable either the igbinary or msgpack PECL extension. Both switch from using
  307. PHP's own human-readable serialized data strucutres to more compact binary
  308. formats.
  309. No specicial configuration is required. If both extensions are enabled,
  310. memcache will automatically use the igbinary extension. If only one extension
  311. is enabled, memcache will automatically use that extension.
  312. You can optionally specify which extension is used by adding one of the
  313. following to your settings.php:
  314. // Force memcache to use PHP's core serialize functions
  315. $conf['memcache_serialize'] = 'serialize';
  316. // Force memcache to use the igbinary serialize functions (if available)
  317. $conf['memcache_serialize'] = 'igbinary';
  318. // Force memcache to use the msgpack serialize functions (if available)
  319. $conf['memcache_serialize'] = 'msgpack';
  320. To review which serialize function is being used, enable the memcache_admin
  321. module and visit admin/reports/memcache.
  322. IGBINARY:
  323. The igbinary project is maintained on GitHub:
  324. - https://github.com/phadej/igbinary
  325. The official igbinary PECL extension can be found at:
  326. - https://pecl.php.net/package/igbinary
  327. Version 2.0.1 or greater is recommended.
  328. MSGPACK:
  329. The msgpack project is maintained at:
  330. - https://msgpack.org
  331. The official msgpack PECL extension can be found at:
  332. - https://pecl.php.net/package/msgpack
  333. Version 2.0.2 or greater is recommended.
  334. ## MAXIMUM LENGTHS ##
  335. If the length of your prefix + key + bin combine to be more than 250 characters,
  336. they will be automatically hashed. Memcache only supports key lengths up to 250
  337. bytes. You can optionally configure the hashing algorithm used, however sha1 was
  338. selected as the default because it performs quickly with minimal collisions.
  339. Visit http://www.php.net/manual/en/function.hash-algos.php to learn more about
  340. which hash algorithms are available.
  341. $conf['memcache_key_hash_algorithm'] = 'sha1';
  342. You can also tune the maximum key length BUT BE AWARE this doesn't affect
  343. memcached's server-side limitations -- this value is primarily exposed to allow
  344. you to further shrink the length of keys to optimize network performance.
  345. Specifying a length larger than 250 will almost certainly lead to problems
  346. unless you know what you're doing.
  347. $conf['memcache_key_max_length'] = 250;
  348. By default, the memcached server can store objects up to 1 MiB in size. It's
  349. possible to increase the memcached page size to support larger objects, but this
  350. can also lead to wasted memory. Alternatively, the Drupal memcache module splits
  351. these large objects into smaller pieces. By default, the Drupal memcache module
  352. splits objects into 1 MiB sized pieces. You can modify this with the following
  353. tunable to match any special server configuration you may have. NOTE: Increasing
  354. this value without making changes to your memcached server can result in
  355. failures to cache large items.
  356. (Note: 1 MiB = 1024 x 1024 = 1048576.)
  357. $conf['memcache_data_max_length'] = 1048576;
  358. It is generally undesirable to store excessively large objects in memcache as
  359. this can result in a performance penalty. Because of this, by default the Drupal
  360. memcache module logs any time an object is cached that has to be split into
  361. multiple pieces. If this is generating too many watchdog logs, you should first
  362. understand why these objects are so large and if anything can be done to make
  363. them smaller. If you determine that the large size is valid and is not causing
  364. you any unnecessary performance penalty, you can tune the following variable to
  365. minimize or disable this logging. Set the value to a positive integer to only
  366. log when an object is split into this many or more pieces. For example, if
  367. memcache_data_max_length is set to 1048576 and memcache_log_data_pieces is set
  368. to 5, watchdog logs will only be written when an object is split into 5 or more
  369. pieces (objects >4 MiB in size). Or, to to completely disable logging set
  370. memcache_log_data_pieces to 0 or FALSE.
  371. $conf['memcache_log_data_pieces'] = 2;
  372. ## MULTIPLE SERVERS ##
  373. To use this module with multiple memcached servers, it is important that you set
  374. the hash strategy to consistent. This is controlled in the PHP extension, not
  375. the Drupal module.
  376. If using PECL memcache:
  377. Edit /etc/php.d/memcache.ini (path may changed based on package/distribution)
  378. and set the following:
  379. memcache.hash_strategy=consistent
  380. You need to reload apache httpd after making that change.
  381. If using PECL memcached:
  382. Memcached options can be controlled in settings.php. The following setting is
  383. needed:
  384. $conf['memcache_options'] = array(
  385. Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  386. );
  387. ## DEBUG LOGGING ##
  388. You can optionally enable debug logging by adding the following to your
  389. settings.php:
  390. $conf['memcache_debug_log'] = '/path/to/file.log';
  391. By default, only the following memcache actions are logged: 'set', 'add',
  392. 'delete', and 'flush'. If you'd like to also log 'get' and 'getMulti' actions,
  393. enble verbose logging:
  394. $conf['memcache_debug_verbose'] = TRUE;
  395. This file needs to be writable by the web server (and/or by drush) or you will
  396. see lots of watchdog errors. You are responsible for ensuring that the debug log
  397. doesn't get too large. By default, enabling debug logging will write logs
  398. looking something like:
  399. 1484719570|add|semaphore|semaphore-memcache_system_list%3Acache_bootstrap|1
  400. 1484719570|set|cache_bootstrap|cache_bootstrap-system_list|1
  401. 1484719570|delete|semaphore|semaphore-memcache_system_list%3Acache_bootstrap|1
  402. The default log format is pipe delineated, containing the following fields:
  403. timestamp|action|bin|cid|return code
  404. You can specify a custom log format by setting the memcache_debug_log_format
  405. variable. Supported variables that will be replaced in your format are:
  406. '!timestamp', '!action', '!bin', '!cid', and '!rc'.
  407. For example, the default log format (note that it includes a new line at the
  408. end) is:
  409. $conf['memcache_debug_log_format'] = "!timestamp|!action|!bin|!cid|!rc\n";
  410. You can change the timestamp format by specifying a PHP date() format string in
  411. the memcache_debug_time_format variable. PHP date() formats are documented at
  412. http://php.net/manual/en/function.date.php. By default timestamps are written as
  413. a unix timestamp. For example:
  414. $conf['memcache_debug_time_format'] = 'U';
  415. ## TROUBLESHOOTING ##
  416. PROBLEM:
  417. Error:
  418. Failed to load required file memcache/dmemcache.inc
  419. Or:
  420. cache_backends not properly configured in settings.php, failed to load
  421. required file memcache.inc
  422. SOLUTION:
  423. You need to enable memcache in settings.php. Search for "Example 1" above
  424. for a basic configuration example.
  425. PROBLEM:
  426. Error:
  427. PECL !extension version %version is unsupported. Please update to
  428. %recommended or newer.
  429. SOLUTION:
  430. Upgrade to the latest available PECL extension release. Older PECL extensions
  431. have known bugs and cause a variety of problems when using the memcache module.
  432. PROBLEM:
  433. Error:
  434. Failed to connect to memcached server instance at <IP ADDRESS>.
  435. SOLUTION:
  436. Verify that the memcached daemon is running at the specified IP and PORT. To
  437. debug you can try to telnet directly to the memcache server from your web
  438. servers, example:
  439. telnet localhost 11211
  440. PROBLEM:
  441. Error:
  442. Failed to store to then retrieve data from memcache.
  443. SOLUTION:
  444. Carefully review your settings.php configuration against the above
  445. documentation. This error simply does a cache_set followed by a cache_get
  446. and confirms that what is written to the cache can then be read back again.
  447. This test was added in the 7.x-1.1 release.
  448. The following code is what performs this test -- you can wrap this in a <?php
  449. tag and execute as a script with 'drush scr' to perform further debugging.
  450. $cid = 'memcache_requirements_test';
  451. $value = 'OK';
  452. // Temporarily store a test value in memcache.
  453. cache_set($cid, $value);
  454. // Retreive the test value from memcache.
  455. $data = cache_get($cid);
  456. if (!isset($data->data) || $data->data !== $value) {
  457. echo t('Failed to store to then retrieve data from memcache.');
  458. }
  459. else {
  460. // Test a delete as well.
  461. cache_clear_all($cid, 'cache');
  462. }
  463. PROBLEM:
  464. Error:
  465. Unexpected failure when testing memcache configuration.
  466. SOLUTION:
  467. Be sure the memcache module is properly installed, and that your settings.php
  468. configuration is correct. This error means an exception was thrown when
  469. attempting to write to and then read from memcache.
  470. PROBLEM:
  471. Error:
  472. Failed to set key: Failed to set key: cache_page-......
  473. SOLUTION:
  474. Upgrade your PECL library to PECL package (2.2.1) (or higher).
  475. WARNING:
  476. Zlib compression at the php.ini level and Memcache conflict.
  477. See http://drupal.org/node/273824
  478. ## MEMCACHE ADMIN ##
  479. A module offering a UI for memcache is included. It provides aggregated and
  480. per-page statistics for memcache.
  481. ## Memcached PECL Extension Support
  482. We also support the Memcached PECL extension. This extension backends
  483. to libmemcached and allows you to use some of the newer advanced features in
  484. memcached 1.4.
  485. NOTE: It is important to realize that the memcache php.ini options do not impact
  486. the memcached extension, this new extension doesn't read in options that way.
  487. Instead, it takes options directly from Drupal. Because of this, you must
  488. configure memcached in settings.php. Please look here for possible options:
  489. http://us2.php.net/manual/en/memcached.constants.php
  490. An example configuration block is below, this block also illustrates our
  491. default options (selected through performance testing). These options will be
  492. set unless overridden in settings.php.
  493. $conf['memcache_options'] = array(
  494. Memcached::OPT_COMPRESSION => FALSE,
  495. Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  496. );
  497. These are as follows:
  498. * Turn off compression, as this takes more CPU cycles than it's worth for most
  499. users
  500. * Turn on consistent distribution, which allows you to add/remove servers
  501. easily
  502. Other options you could experiment with:
  503. + Memcached::OPT_BINARY_PROTOCOL => TRUE,
  504. * This enables the Memcache binary protocol (only available in Memcached
  505. 1.4 and later). Note that some users have reported SLOWER performance
  506. with this feature enabled. It should only be enabled on extremely high
  507. traffic networks where memcache network traffic is a bottleneck.
  508. Additional reading about the binary protocol:
  509. http://code.google.com/p/memcached/wiki/MemcacheBinaryProtocol
  510. + Memcached::OPT_TCP_NODELAY => TRUE,
  511. * This enables the no-delay feature for connecting sockets; it's been
  512. reported that this can speed up the Binary protocol (see above). This
  513. tells the TCP stack to send packets immediately and without waiting for
  514. a full payload, reducing per-packet network latency (disabling "Nagling").
  515. It's possible to enable SASL authentication as documented here:
  516. http://php.net/manual/en/memcached.setsaslauthdata.php
  517. https://code.google.com/p/memcached/wiki/SASLHowto
  518. SASL authentication requires a memcached server with SASL support (version 1.4.3
  519. or greater built with --enable-sasl and started with the -S flag) and the PECL
  520. memcached client version 2.0.0 or greater also built with SASL support. Once
  521. these requirements are satisfied you can then enable SASL support in the Drupal
  522. memcache module by enabling the binary protocol and setting
  523. memcache_sasl_username and memcache_sasl_password in settings.php. For example:
  524. $conf['memcache_options'] = array(
  525. Memcached::OPT_BINARY_PROTOCOL => TRUE,
  526. );
  527. $conf['memcache_sasl_username'] = 'yourSASLUsername';
  528. $conf['memcache_sasl_password'] = 'yourSASLPassword';
  529. ## Amazon Elasticache
  530. You can use the Drupal Memcache module to talk with Amazon Elasticache, but to
  531. enable Automatic Discovery you must use Amazon's forked version of the PECL
  532. Memcached extension with Dynamic Client Mode enabled.
  533. Their PECL Memcached fork is maintained on GitHub:
  534. - https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php
  535. If you are using PHP 7 you need to select the php7 branch of their project.
  536. Once the extension is installed, you can enable Dynamic Client Mode as follows:
  537. $conf['memcache_options'] = array(
  538. Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  539. Memcached::OPT_CLIENT_MODE => Memcached::DYNAMIC_CLIENT_MODE,
  540. );
  541. You then configure the module normally. Amazon explains:
  542. "If you use Automatic Discovery, you can use the cluster's Configuration
  543. Endpoint to configure your Memcached client."
  544. The Configuration Endpoint must have 'cfg' in the name or it won't work. Further
  545. documentation can be found here:
  546. http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Endpoints.html
  547. If you don't want to use Automatic Discovery you don't need to install the
  548. forked PECL extension, Amazon explains:
  549. "If you don't use Automatic Discovery, you must configure your client to use
  550. the individual node endpoints for reads and writes. You must also keep track
  551. of them as you add and remove nodes."