A
A
Anatoly2020-02-21 08:41:12
*nix-like systems
Anatoly, 2020-02-21 08:41:12

How to connect memcached (memcache) in Wordpress?

Debian 10, php7.4, memcache, memcached, unix socket.

How to connect memcached to wordpress?
QueryMonitor reports:
PHP Memcache extension installed but not used by WordPress
PHP Memcached extension installed but not used by WordPress


What was done:

1) Installed extensions and server
apt install php-memcached php-memcache memcached

2) Set up
nano /etc/memcached.conf
-s /var/run/memcached/memcached.sock
-a 0755
-d
-u nginx
-m 64
-P /var/run/memcached/memcached.pid
mkdir /var/run/memcached -m 0755
chown -R nginx:nginx /var/run/memcached
systemctl restart memcached php7.4-fpm

3) Checked the work
netstat -an | grep memcached
и скриптом
<?php
$memcache_obj = new Memcache;
$memcache_obj->addServer('unix:///var/run/memcached/memcached.sock',0);
$status = $memcache_obj->getStats();
$MBUsed= (real)$status["bytes"]/(1024*1024);
$MBSize=(real) $status["limit_maxbytes"]/(1024*1024);
?>
Статистика Memcache:
<table border='1'>
   <tr><td>Версия Memcache сервера</td><td> <?=$status ["version"];?></td></tr>
   <tr><td>Время работы Memcache (в секундах) </td><td><?=$status ["uptime"];?></td></tr>
   <tr><td>Максимальный объем памяти для Memcache</td><td><?=$MBSize;?> Мб</td></tr>
   <tr><td>Используется памяти</td><td><? printf("%.2f",$MBUsed);?> Мб</td></tr>
</table>
?>

4) Connected to WP
1) Скопировал файлы object-cache* из https://github.com/bonny/memcachy
в папку /wp-content/
2) В config.php дописал:
$memcached_servers = array('unix:///var/run/memcached/memcached.sock');
3) Установил плагин Batcache:
  • Скачиваем файл со страницы https://WordPress.org/plugins/batcache/
  • Файл advanced-cache.php копируем в папку /wp-content/
  • Файл batcache.php в директорию /wp-content/plugins/
  • В файле wp-config.php добавляем строку: define('WP_CACHE', true);
  • Активируем плагин
  • В документе под тегом head должно быть подтверждения активности плагина - но его нет



What I got:
Object cache statistics are not available
External object caching is used

As a result, when loading any page, it makes thousands of requests to the database, and instead of 1-2 seconds, you have to wait 10 seconds.

I feel there is a catch somewhere, but I can’t understand where.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question