Install
Works with Drupal: 7.xUsing Composer to manage Drupal site dependencies
Downloads
Release notes
Narrowing In On A New Release
Help us test 7.x-1.6-rc3 to make sure there are no regressions compared to 7.x-1.5. Lots of bug fixes and useful new features were included in this release. The README is fully updated, documenting all new features that require configuration.
Always carefully test the update process and new release first in a development and/or staging environment before updating your production environment!
Highlights
- Persistent connections are now enabled by default.
- Introducing two memcache-specific drush commands; instantly flush an entire bin:
drush mcf
, review server statistics:drush mcs
. - Improved debug output when memcache is misconfigured.
- Properly handle over-sized cache items.
- Support for the 'igbinary' and 'msgpack' extensions, optionally replacing php's serialize functions
- PHP 7 support
What’s changed since 7.x-1.6-rc2
- #332094: Add support for server weight
New feature: add support for specifying server weight - #2376391: Call to undefined function lock_acquire()
Fix error "Call to undefined function lock_acquire()" when using PECL Memcached - #2848252: drush clear-cache results in: array_merge(): Argument #2 is not an array dmemcache.inc:404
Fix regression: fix error "array_merge(): Argument #2 is not an array" - #2850974: Watchdog notices: "Undefined variable: full_key"
Fix regression: fix watchdog notice "Undefined variable: full_key"
Overview
It's been two years since the last Drupal Memcache module release! Perhaps it's no coincidence that I also have a nearly two-year-old daughter. Excuses aside, there's a ton of important changes in this release, from optimizations and bug fixes to new features. What follows was extracted from the README.txt:
Drush
Enable the memcache module at admin/modules or with 'drush en memcache', then rebuild the drush cache by running 'drush cc drush'. This will enable the following drush commands:
memcache-flush (mcf) Flush all Memcached objects in a bin.
memcache-stats (mcs) Retrieve statistics from Memcached.
For more information about each command, use 'drush help'. For example:
drush help mcf
Or:
drush help mcs
Cache lifetime
Memcache respects Drupal core's minimum cache lifetime configuration. This setting affects all cached items, not just pages. In some cases, it may be desirable to cache different types of items for different amounts of time. You can override the minimum cache lifetime on a per-bin basis in settings.php. For example:
// Cache pages for 60 seconds.
$conf['cache_lifetime_cache_page'] = 60;
// Cache menus for 10 minutes.
$conf['cache_lifetime_menu'] = 600;
Cache header
Drupal core indicates whether or not a page was served out of the cache by setting the 'X-Drupal-Cache' response header with a value of HIT or MISS. If you'd like to confirm whether pages are actually being retreived from Memcache and not another backend, you can enable the following option:
$conf['memcache_pagecache_header'] = TRUE;
When enabled, the Memcache module will add its own 'Drupal-Pagecache-Memcache' header. When cached pages are served out of the cache the header will include an 'age=' value indicating how many seconds ago the page was stored in the cache.
Persistent connections
As of 7.x-1.6, the memcache module uses peristent connections by default. If this causes you problems you can disable persistent connections by adding the following to your settings.php:
$conf['memcache_persistent'] = FALSE;
Weighting servers
By default, all servers within a cluster have a weight of one, such as in this example:
$conf['memcache_servers'] = array(
'192.168.1.1:11211' => 'default',
'192.168.1.2:11211' => 'default',
);
You can optionally assign a different weight to each server, making it possible to favor one server more than another. To do so, you define the cluster within an array. For example, to make it 3 times more likely to store an item in the first server versus the second:
$conf['memcache_servers'] = array(
'192.168.1.1:11211' => array('cluster' => 'default', 'weight' => 3),
'192.168.1.2:11211' => array('cluster' => 'default', 'weight' => 1),
);
If the weight is not specified it defaults to 1, so the following configuration is identical to the above:
$conf['memcache_servers'] = array(
'192.168.1.1:11211' => array('cluster' => 'default', 'weight' => 3),
'192.168.1.2:11211' => '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 $conf array of settings.php. This can be a single string prefix, or a keyed array of bin => prefix pairs:
$conf['memcache_key_prefix'] = 'something_unique';
Using a per-bin prefix:
$conf['memcache_key_prefix'] = array(
'default' => 'something_unique',
'cache_page' => 'something_else_unique'
);
In the above example, the 'something_unique' prefix will be used for all bins except for the 'cache_page' bin which will use the 'something_else_unique' prefix. Note that if using a keyed array for specifying prefix, you must specify the 'default' prefix.
It is also possible to specify multiple prefixes per bin. Only the first prefix will be used when setting/getting cache items, but all prefixes will be cleared when deleting cache items. This provides support for more complicated configurations such as a live instance and an administrative instance each with their own prefixes and therefore their own unique caches. Any time a cache item is deleted on either instance, it gets flushed on both -- thus, should an admin do something that flushes the page cache, it will appropriately get flushed on both instances. (For more discussion see the issue where support was added, https://www.drupal.org/node/1084448.) This feature is enabled when you configure prefixes as arrays within arrays. For example:
// Live instance.
$conf['memcache_key_prefix'] = array(
'default' => array(
'live_unique', // live cache prefix
'admin_unique', // admin cache prefix
),
);
The above would be the configuration of your live instance. Then, on your administrative instance you would flip the keys:
// Administrative instance.
$conf['memcache_key_prefix'] = array(
'default' => array(
'admin_unique', // admin cache prefix
'live_unique', // live cache prefix
),
);
Experimental - Alternative Serialize
This is a new experimental feature added to the memcache module in version 7.x-1.6 and should be tested carefully before utilizing in production.
To optimize how data is serialized before it is written to memcache, you can enable either the igbinary or msgpack PECL extension. Both switch from using PHP's own human-readable serialized data strucutres to more compact binary formats.
No specicial configuration is required. If both extensions are enabled, memcache will automatically use the igbinary extension. If only one extension is enabled, memcache will automatically use that extension.
You can optionally specify which extension is used by adding one of the following to your settings.php:
// Force memcache to use PHP's core serialize functions
$conf['memcache_serialize'] = 'serialize';
// Force memcache to use the igbinary serialize functions (if available)
$conf['memcache_serialize'] = 'igbinary';
// Force memcache to use the msgpack serialize functions (if available)
$conf['memcache_serialize'] = 'msgpack';
To review which serialize function is being used, enable the memcache_admin
module and visit admin/reports/memcache.
IGBINARY
The igbinary project is maintained on GitHub:
- https://github.com/phadej/igbinary
The official igbinary PECL extension can be found at:
- https://pecl.php.net/package/igbinary
Version 2.0.1 or greater is recommended.
MSGPACK
The msgpack project is maintained at:
- https://msgpack.org
The official msgpack PECL extension can be found at:
- https://pecl.php.net/package/msgpack
Version 2.0.2 or greater is recommended.
Debug logging
You can optionally enable debug logging by adding the following to your settings.php:
$conf['memcache_debug_log'] = '/path/to/file.log';
By default, only the following memcache actions are logged: 'set', 'add', 'delete', and 'flush'. If you'd like to also log 'get' and 'getMulti' actions, enble verbose logging:
$conf['memcache_debug_verbose'] = TRUE;
This file needs to be writable by the web server (and/or by drush) or you will see lots of watchdog errors. You are responsible for ensuring that the debug log doesn't get too large. By default, enabling debug logging will write logs looking something like:
1484719570|add|semaphore|semaphore-memcache_system_list%3Acache_bootstrap|1
1484719570|set|cache_bootstrap|cache_bootstrap-system_list|1
1484719570|delete|semaphore|semaphore-memcache_system_list%3Acache_bootstrap|1
The default log format is pipe delineated, containing the following fields:
timestamp|action|bin|cid|return code
You can specify a custom log format by setting the memcache_debug_log_format variable. Supported variables that will be replaced in your format are: '!timestamp', '!action', '!bin', '!cid', and '!rc'. For example, the default log format (note that it includes a new line at the
end) is:
$conf['memcache_debug_log_format'] = "!timestamp|!action|!bin|!cid|!rc\n";
You can change the timestamp format by specifying a PHP date() format string in the memcache_debug_time_format variable. PHP date() formats are documented at http://php.net/manual/en/function.date.php. By default timestamps are written as a unix timestamp. For example:
$conf['memcache_debug_time_format'] = 'U';
Amazon Elasticache
You can use the Drupal Memcache module to talk with Amazon Elasticache, but to enable Automatic Discovery you must use Amazon's forked version of the PECL Memcached extension with Dynamic Client Mode enabled.
Their PECL Memcached fork is maintained on GitHub:
- https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php
If you are using PHP 7 you need to select the php7 branch of their project.
Once the extension is installed, you can enable Dynamic Client Mode as follows:
$conf['memcache_options'] = array(
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
Memcached::OPT_CLIENT_MODE => Memcached::DYNAMIC_CLIENT_MODE,
);
You then configure the module normally. Amazon explains:
"If you use Automatic Discovery, you can use the cluster's Configuration
Endpoint to configure your Memcached client."
The Configuration Endpoint must have 'cfg' in the name or it won't work. Further documentation can be found here:
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Endpoints....
If you don't want to use Automatic Discovery you don't need to install the
forked PECL extension, Amazon explains:
"If you don't use Automatic Discovery, you must configure your client to use
the individual node endpoints for reads and writes. You must also keep track
of them as you add and remove nodes."
Details
- #332094: Add support for server weight
New feature: support specifying server weight - #467226: Support for per-bin key prefix
New feature: support setting unique per-bin prefixes - #903914: Per-bin minimum cache lifetime
New feature: support configuring a per-bin minimum cache lifetime - #948132: Clean up old $_SESSION['cache_flush'] data
Cleanup _SESSION variable that temporarily keeps individual users from loading from cache - #1084448: Clear multiple prefixes at once
New feature: ability to delete keys with multiple prefixes (adds support for an administrative instance separate from the production instance) - #1305696: substr() expects parameter 3 to be long, string given memcache.inc
Introduce 'Invalid cache id received in memcache.inc wildcards() of type ___' error, trying to track down intermittent failures; Fix regression: Invalid cache id received in memcache.inc wildcards() of type integer - #1508574: Remove memcache extension dependency in dmemcache.inc
Consistency cleanup - #1528228: Using Memcache API with AWS (Amazon) Elasticache
Document how to use the Memcache module with Amazon Elasticache; Improve ElastiCache documentation - #1863996: Fix all tests
Wow, tests are finally all working! - #1864624: Add timestamp of creation on pages
New feature: introduced Drupal-Pagecache-Memcache header with details about how long a page has been cached. To enable,$conf['memcache_pagecache_header'] = TRUE;
- #1896452: Active memcache more than doubles cache clear/menu rebuild time.
Optimize variable_set calls when the value hasn't actually changed - #1977452: Add persistent connection support for the PECL Memcached extension
Enable persistent connections by default, added persistent connection support to PECL Memcached. To disable,$conf['memcache_persistent'] = FALSE;
- #1993170: Add Drush command to retrieve Memcached values
New feature: Learn more:drush help mcf
anddrush help mcs
- #2241639: Clarifications on memcache sessions handling for D7
Session support never worked correctly in Drupal 7, removing - #2328707: Call to undefined function dmemcache_stats()
Improve debug output when memcache is misconfigured - #2365839: Provide introspection tool
New feature: debug logging. To enable,$conf['memcache_debug_log'] = '/tmp/memcache.log';
To increase verbosity,$conf['memcache_debug_verbose'] = TRUE;
- #2376391: Call to undefined function lock_acquire()
Fix error "Call to undefined function lock_acquire()" when using PECL Memcached - #2413663: Notice: Undefined index: httprl lock_release memcache
Don't free locks we don't own - #2415109: Notice: unserialize(): Error at offset 0 of 2527853 bytes in _dmemcache_get_pieces() (line 329 of modules/memcache/dmemcache.inc).
Nasty bug where large items often weren't put back together correctly - #2419757: Stampede Protection can cause performance degradation for some cache bins
Disable stampede protection for cache_path and lookup_cache - #2422871: Undefined offset: 1 in dmemcache_connect()
Improve debug output when memcache is misconfigured - #2444773: Update README.txt file
Add reference to online installation documentation - #2556999: CK editor fields are populated with Memcache stats
Let's play together nicely - #2542984: Replace $_SERVER['REQUEST_TIME'] with REQUEST_TIME
Cleanup - #2696129: Performance of serialization
New feature: replace php serialize with igbinary or msgpack. To disable,$conf['memcache_serialize'] = 'serialize';
For more, review the README. - #2733947: Add compatibility with PHP 7 for method call \Memcached::getMulti()
Support getMulti with PHP 7 - #2757895: dmemcache_object() should log the bin being accessed on connection error
Improved connection failure logging - #2771947: Memcache works incorrect with Sasl auth
Fix support for memcache->setSaslAuthData with username and password - #2828888: Add _drupal_file_scan_cache to memcache_stampede_protection_ignore
Disable stampede protection for _drupal_file_scan_cache - #2848252: drush clear-cache results in: array_merge(): Argument #2 is not an array dmemcache.inc:404
Fix regression: fix error "array_merge(): Argument #2 is not an array" - #2850974: Watchdog notices: "Undefined variable: full_key"
Fix regression: fix watchdog notice "Undefined variable: full_key"
Testing
The memcache module is a critical component of even the largest Drupal websites, so we take testing seriously. We have done comprehensive load testing of this release to ensure that there have been no performance regressions. Our load tests are freely available at https://github.com/tag1consulting/drupal-loadtest. There you will find scripts that assist in pre-populating a site with data and running a jMeter loadtest suite against the test website. While the tests aren’t comprehensive and only focus on common core functionality, they provide fantastic insight and detail into the performance differences between releases.