Just a note that the PECL memcached extension doesn’t work with PHP 7.3 yet, you need to stay on PHP 7.2.
This is the error I got when trying to running
sudo perl install memcached (along with several sasl deprecation warnings):
/private/tmp/pear/install/memcached/php_memcached.c:1284:20: error: expression is not assignable
NB: Also, don’t get memcache and memcached mixed up when searching extensions.
- Make sure phpinfo(); (available at /admin/reports/status/php in Drupal for administrators) contains a memcached section – by default Lando will install the memcached PECL package.
- Install and enable memcache Drupal module.
- configure settings.php:
$settings['memcache']['servers'] = ['cache:11211' => 'default'];
$settings['memcache']['bins'] = ['default' => 'default'];
$settings['memcache']['key_prefix'] = 'mysitename_';
$settings['cache']['default'] = 'cache.backend.memcache';
Note the hostname for external connections (port 11222) is localhost, but internal connections have a different hostname: cache – to verify, run
(give it the correct sitename – this is especially important if you ever use memcached for two or more sites on the same server, to avoid conflicts.
Also, note memcached has no security so if an application knows or can guess another applications’ prefix it can read all the data.
- Truncate all MySQL tables beginning with
cache (Drupal bootstraps from the database by default and otherwise may continue to use them)
- Run drush cr
- You can should now work.
Verify connection and performance (e.g. hits/misses and memory used) at /admin/reports/memcache
Way to test an internal connection from PHP in a container, if you can’t install what you need:
> $socket = fsockopen('cache', "11211", $errno, $errstr);
If you don’t see any errors, it has connected.