You are here

README.txt in Memcache API and Integration 5

Same filename and directory in other branches
  1. 8.2 README.txt
  2. 5.2 README.txt
  3. 6 README.txt
  4. 7 README.txt
## Requirements ##

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

## INSTALLATION ##

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

1. Install the memcached binaries on your server. See http://www.lullabot.com/articles/how_install_memcache_debian_etch
2. Install the PECL memcache extension for PHP. This must be version 2.2.1 or higher or you will experience errors.
3. Put your site into offline mode.
4. Download and install the memcache module.
5. If you have previously been running the memcache module, run update.php.
6. Apply the DRUPAL-5-x-cache-serialize.patch from the patches folder that
   comes with the module.  Version specific, so use DRUPAL-5-6-cache-serialize.patch
   if you are running Drupal 5.6.
7. Start at least one instance of memcached on your server.
8. Edit settings.php to configure the servers, clusters and bins that memcache
   is supposed to use.
9. Edit settings.php to include either memcache.inc or memcache.db.inc. For
   example, $conf['cache_inc'] ='sites/all/modules/memcache/memcache.db.inc';
10. Bring your site back online.

For instructions on 1 and 2 above, please see the INSTALLATION.txt file that
comes with the memcache module download.

Either the memcache.inc or the memcache.db.inc file is intended to be used
instead of cache.inc, utilizing Drupal's pluggable cache system. The .db.inc
variant saves all data to the database as well, so the site will still have
the performance benefits of cache even if you take your memcache offline. The
site should not ever break due to memcache not being available... it is only
a question of whether caching is still available or not. The memcache.inc file
doesn't save any data to the database and thus has the biggest potential for
increasing your site's performance. If you use this file it is important to
have enough memory allocated to memcache to store everything (including the page
cache), otherwise the cache misses will negate the benefit of the cache hits.

Update $conf in settings.php to tell Drupal which cache_inc file to use:

 $conf = array(
   // The path to wherever memcache.inc is. The easiest is to simply point it
   // to the copy in your module's directory.
   'cache_inc' => './sites/all/modules/memcache/memcache.inc',
   // or
   // 'cache_inc' => './sites/all/modules/memcache/memcache.db.inc',
 );

## SERVERS ##

If you want the simple version, you can start one default memcache instance on
your web server like this: memcached -m 24 -p 11211 -d
If that is enough to meet your needs, there is no more configuration needed. If
you want to utilize this module's sophisticated clustering feature and spread
your cache over several machines, or if your cache is found on a machine other
than your web server, read on.

The available memcached servers are specified in $conf in settings.php. If
you do not specify any servers, memcache.inc assumes that you have a
memcached instance running on localhost:11211. If this is true, and it is
the only memcached instance you wish to use, no further configuration is
required.

If you have more than one memcached instance running, you need to add two
arrays to $conf; memcache_servers and memcache_bins. The arrays follow this
pattern:

'memcache_servers' => array(host1:port => cluster, host2:port => cluster, hostN:port => cluster)

'memcache_bins' => array(bin1 => cluster, bin2 => cluster, binN => cluster)

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

- Servers are memcached instances identified by host:port.

- Bins are groups of data that get cached together and map 1:1 to the $table
  param in cache_set(). Examples from Drupal core are cache_filter,
  cache_menu. The default is 'cache'.

- Clusters are groups of servers that act as a memory pool.

- many bins can be assigned to a cluster.

- The default cluster is 'default'.

Here is a simple setup that has two memcached instances, both running on
localhost. The 11212 instance belongs to the 'pages' cluster and the table
cache_page is mapped to the 'pages' cluster. Thus everything that gets cached,
with the exception of the page cache (cache_page), will be put into 'default',
or the 11211 instance. The page cache will be in 11212.

$conf = array(
  ...
  // Important to define a default cluster in both the servers
  // and in the bins. This links them together.
  'memcache_servers' => array('localhost:11211' => 'default',
                              'localhost:11212' => 'pages'),
  'memcache_bins' => array('cache' => 'default',
                           'cache_page' => 'pages'),
);

Here is an example configuration that has two clusters, 'default' and
'cluster2'. Five memcached instances are divided up between the two
clusters. 'cache_filter' and 'cache_menu' bins goe to 'cluster2'. All other
bins go to 'default'.

$conf = array(
  'cache_inc' => './includes/memcache.inc',
  'memcache_servers' => array('localhost:11211' => 'default',
                              'localhost:11212' => 'default',
                              '123.45.67.890:11211' => 'default',
                              '123.45.67.891:11211' => 'cluster2',
                              '123.45.67.892:11211' => 'cluster2'),

  'memcache_bins' => array('cache' => 'default',
                           'cache_filter' => 'cluster2',
                           'cache_menu' => 'cluster2'),
);
## 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 $conf
array of settings.php:

$conf = array(
  ...
  'memcache_key_prefix' => 'something_unique',
);

## PATCHES ##

The DRUPAL-5-cache-serialize.patch must be applied to your Drupal installation
for this software to work. The patch depends on a column that needs to get added
to all of the existing cache tables for your site. This column has been
introduced in the DRUPAL-6 development branch so this patch is future-safe if
you ever upgrade to DRUPAL-6. To actually add the column to your database, you
need to either install the memcache.module, or, if it is already installed and
you are updating to this version, run update.php. Either installing the module
or running update.php will add the needed column, Uninstalling the module will
remove the column.

## TROUBLESHOOTING ##

PROBLEM:
Warning: require_once(a) [function.require-once]: failed to open stream:
No such file or directory in /includes/bootstrap.inc on line 853

SOLUTION:
This error occurs after you apply the DRUPAL-5-cache-serialize.patch because
the code in the patch now expects the cached variables to be unserialized
but they are still serialized in the cache. Clear the cache table:

mysql> TRUNCATE cache;
Query OK, 0 rows affected (0.01 sec)

PROBLEM:
Fatal error: Cannot use string offset as an array in includes/menu.inc on line 452

SOLUTION:
Similar to the error above, this occurs after applying the
DRUPAL-5-cache-serialize.patch due to the conflict between the existing
cached menu and what the patched code is expecting. Clear cache_menu:

mysql> TRUNCATE cache_menu;
Query OK, 0 rows affected (0.33 sec)

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 on the way. It will provide stats, a
way to clear the cache, and an interface to organize servers/bins/clusters.

File

README.txt
View source
  1. ## Requirements ##
  2. - PHP 5.1 or greater
  3. - Availability of a memcached daemon: http://memcached.org/
  4. - One of the two PECL memcache packages:
  5. - http://pecl.php.net/package/memcache
  6. - http://pecl.php.net/package/memcached (recommended
  7. ## INSTALLATION ##
  8. These are the broad steps you need to take in order to use this software. Order
  9. is important.
  10. 1. Install the memcached binaries on your server. See http://www.lullabot.com/articles/how_install_memcache_debian_etch
  11. 2. Install the PECL memcache extension for PHP. This must be version 2.2.1 or higher or you will experience errors.
  12. 3. Put your site into offline mode.
  13. 4. Download and install the memcache module.
  14. 5. If you have previously been running the memcache module, run update.php.
  15. 6. Apply the DRUPAL-5-x-cache-serialize.patch from the patches folder that
  16. comes with the module. Version specific, so use DRUPAL-5-6-cache-serialize.patch
  17. if you are running Drupal 5.6.
  18. 7. Start at least one instance of memcached on your server.
  19. 8. Edit settings.php to configure the servers, clusters and bins that memcache
  20. is supposed to use.
  21. 9. Edit settings.php to include either memcache.inc or memcache.db.inc. For
  22. example, $conf['cache_inc'] ='sites/all/modules/memcache/memcache.db.inc';
  23. 10. Bring your site back online.
  24. For instructions on 1 and 2 above, please see the INSTALLATION.txt file that
  25. comes with the memcache module download.
  26. Either the memcache.inc or the memcache.db.inc file is intended to be used
  27. instead of cache.inc, utilizing Drupal's pluggable cache system. The .db.inc
  28. variant saves all data to the database as well, so the site will still have
  29. the performance benefits of cache even if you take your memcache offline. The
  30. site should not ever break due to memcache not being available... it is only
  31. a question of whether caching is still available or not. The memcache.inc file
  32. doesn't save any data to the database and thus has the biggest potential for
  33. increasing your site's performance. If you use this file it is important to
  34. have enough memory allocated to memcache to store everything (including the page
  35. cache), otherwise the cache misses will negate the benefit of the cache hits.
  36. Update $conf in settings.php to tell Drupal which cache_inc file to use:
  37. $conf = array(
  38. // The path to wherever memcache.inc is. The easiest is to simply point it
  39. // to the copy in your module's directory.
  40. 'cache_inc' => './sites/all/modules/memcache/memcache.inc',
  41. // or
  42. // 'cache_inc' => './sites/all/modules/memcache/memcache.db.inc',
  43. );
  44. ## SERVERS ##
  45. If you want the simple version, you can start one default memcache instance on
  46. your web server like this: memcached -m 24 -p 11211 -d
  47. If that is enough to meet your needs, there is no more configuration needed. If
  48. you want to utilize this module's sophisticated clustering feature and spread
  49. your cache over several machines, or if your cache is found on a machine other
  50. than your web server, read on.
  51. The available memcached servers are specified in $conf in settings.php. If
  52. you do not specify any servers, memcache.inc assumes that you have a
  53. memcached instance running on localhost:11211. If this is true, and it is
  54. the only memcached instance you wish to use, no further configuration is
  55. required.
  56. If you have more than one memcached instance running, you need to add two
  57. arrays to $conf; memcache_servers and memcache_bins. The arrays follow this
  58. pattern:
  59. 'memcache_servers' => array(host1:port => cluster, host2:port => cluster, hostN:port => cluster)
  60. 'memcache_bins' => array(bin1 => cluster, bin2 => cluster, binN => cluster)
  61. The bin/cluster/server model can be described as follows:
  62. - Servers are memcached instances identified by host:port.
  63. - Bins are groups of data that get cached together and map 1:1 to the $table
  64. param in cache_set(). Examples from Drupal core are cache_filter,
  65. cache_menu. The default is 'cache'.
  66. - Clusters are groups of servers that act as a memory pool.
  67. - many bins can be assigned to a cluster.
  68. - The default cluster is 'default'.
  69. Here is a simple setup that has two memcached instances, both running on
  70. localhost. The 11212 instance belongs to the 'pages' cluster and the table
  71. cache_page is mapped to the 'pages' cluster. Thus everything that gets cached,
  72. with the exception of the page cache (cache_page), will be put into 'default',
  73. or the 11211 instance. The page cache will be in 11212.
  74. $conf = array(
  75. ...
  76. // Important to define a default cluster in both the servers
  77. // and in the bins. This links them together.
  78. 'memcache_servers' => array('localhost:11211' => 'default',
  79. 'localhost:11212' => 'pages'),
  80. 'memcache_bins' => array('cache' => 'default',
  81. 'cache_page' => 'pages'),
  82. );
  83. Here is an example configuration that has two clusters, 'default' and
  84. 'cluster2'. Five memcached instances are divided up between the two
  85. clusters. 'cache_filter' and 'cache_menu' bins goe to 'cluster2'. All other
  86. bins go to 'default'.
  87. $conf = array(
  88. 'cache_inc' => './includes/memcache.inc',
  89. 'memcache_servers' => array('localhost:11211' => 'default',
  90. 'localhost:11212' => 'default',
  91. '123.45.67.890:11211' => 'default',
  92. '123.45.67.891:11211' => 'cluster2',
  93. '123.45.67.892:11211' => 'cluster2'),
  94. 'memcache_bins' => array('cache' => 'default',
  95. 'cache_filter' => 'cluster2',
  96. 'cache_menu' => 'cluster2'),
  97. );
  98. ## PREFIXING ##
  99. If you want to have multiple Drupal installations share memcached instances,
  100. you need to include a unique prefix for each Drupal installation in the $conf
  101. array of settings.php:
  102. $conf = array(
  103. ...
  104. 'memcache_key_prefix' => 'something_unique',
  105. );
  106. ## PATCHES ##
  107. The DRUPAL-5-cache-serialize.patch must be applied to your Drupal installation
  108. for this software to work. The patch depends on a column that needs to get added
  109. to all of the existing cache tables for your site. This column has been
  110. introduced in the DRUPAL-6 development branch so this patch is future-safe if
  111. you ever upgrade to DRUPAL-6. To actually add the column to your database, you
  112. need to either install the memcache.module, or, if it is already installed and
  113. you are updating to this version, run update.php. Either installing the module
  114. or running update.php will add the needed column, Uninstalling the module will
  115. remove the column.
  116. ## TROUBLESHOOTING ##
  117. PROBLEM:
  118. Warning: require_once(a) [function.require-once]: failed to open stream:
  119. No such file or directory in /includes/bootstrap.inc on line 853
  120. SOLUTION:
  121. This error occurs after you apply the DRUPAL-5-cache-serialize.patch because
  122. the code in the patch now expects the cached variables to be unserialized
  123. but they are still serialized in the cache. Clear the cache table:
  124. mysql> TRUNCATE cache;
  125. Query OK, 0 rows affected (0.01 sec)
  126. PROBLEM:
  127. Fatal error: Cannot use string offset as an array in includes/menu.inc on line 452
  128. SOLUTION:
  129. Similar to the error above, this occurs after applying the
  130. DRUPAL-5-cache-serialize.patch due to the conflict between the existing
  131. cached menu and what the patched code is expecting. Clear cache_menu:
  132. mysql> TRUNCATE cache_menu;
  133. Query OK, 0 rows affected (0.33 sec)
  134. PROBLEM:
  135. Error:
  136. Failed to set key: Failed to set key: cache_page-......
  137. SOLUTION:
  138. Upgrade your PECL library to PECL package (2.2.1) (or higher).
  139. WARNING:
  140. Zlib compression at the php.ini level and Memcache conflict. See http://drupal.org/node/273824
  141. ## MEMCACHE ADMIN ##
  142. A module offering a UI for memcache is on the way. It will provide stats, a
  143. way to clear the cache, and an interface to organize servers/bins/clusters.