memcache

Since we moved to PHP 5.5 and it’s built in zend opcache, we decided to stop using APC.

Since zend opcache filled opcaching need only, we needed something for data-cache. There is one APC fork trying to extract data-caching code on Github. But we wanted something stable and mature so we choose to go with memcache.

I always hated presence of php5-memcache and php5-memcached – two solutions for similar needs. I read this and this and many more threads but could reach a conclusion.

Actually for our trivial needs both extensions should work fine. But we (forced) to choose php5-memcache as w3-total-cache doesn’t support only this!

Installation

apt-get install memcached php5-memcache
service php5-fpm restart

Config

Increase Max Memory memcache can use

By default, its 64MB. You may need more.

  1. Open /etc/memcached.conf 
  2. Look for value -m 64
  3. Change it to -m 1024
  4. Restart memcached  service memcached restart

Move PHP’s session storage to memcache

Open /etc/php5/mods-available/memcache.ini

Add following lines:

session.save_handler = memcache
session.save_path = "tcp://localhost:11211"

Extra: Since memcached can works in multiserver mode, you can share session across server. Google for more info on this. I will post our config when we will write one! 😉

Changes in w3-total-cache plugin

In w3-total-cache plugin you need to choose memcache as backend for object-cache and database-cache.

Web-based Stats Viewer for Memcache

There are many but we choose phpmemcacheadmin

cd /var/www/example.com/htdocs/
mkdir mem && cd mem
wget http://phpmemcacheadmin.googlecode.com/files/phpMemcachedAdmin-1.2.2-r262.tar.gz
tar -xvzf phpMemcachedAdmin-1.2.2-r262.tar.gz
chmod +r *
chmod 0777 Config/Memcache.php