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!


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


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/
mkdir mem && cd mem
tar -xvzf phpMemcachedAdmin-1.2.2-r262.tar.gz
chmod +r *
chmod 0777 Config/Memcache.php



  1. RavanH Avatar

    Hi, as soon as I set session.save_handler = memcache (and restart php5) I get PHP Internal Server Errors all around… I cannot for the life of me figure out why ;(
    Can anyone share some tips on debugging this?

    1. Rahul Bansal Avatar

      There are many things which can possibly go wrong. Please check error log for site.

  2. Guill Avatar

    I’m using also php5.5 with the zend optimiser. I’ve got issues each time I save the settings in W3TC. I think the setting page is cached by the zend optimiser (not by nginx) so the only way to see the changes is to force a browser refresh. Weird. Any way to force the zend optimiser to check the cache for each request? (like apc stat 0)

    1. Rahul Bansal Avatar

      You may need following as described in

      1. Guill Avatar

        Oups, missed these 2 lines. Thank you Rahul!

  3. Alex Avatar

    So, i use php 5.3…and want use memcached also
    when i uncomment memcache.ini

    session.save_handler = memcache
    session.save_path = “tcp://”

    my WP not work, blank page
    memcached server is starting of course…and config to -l

    1. Rahul Bansal Avatar

      You can leave session related 2 lines commented.

      Some bad plugins do not work with memcache-based sessions.

  4. DeAndre Johnson Avatar

    Have you considered the pros and cons of redis vs memcache?

    1. Rahul Bansal Avatar

      Yes. It seems redis is faster but did not proper support for redis in wordpress & nginx world. So for now using memcache.

      Also difference is too small to matter for WordPress/content sites.

  5. ari Avatar

    Just to add that if installing all this you need to do service php5-fpm restart so w3-total cache will recognize the install

    1. Rahul Bansal Avatar

      Thanks for comment. 🙂

      I missed that. I have updated article so php will detect memcache module.

  6. SID Avatar

    When i’m trying connect to memcache-server using connect – all work very good. But when i trying use addServer – I all time see error timeout connect to server.
    Can you help?

    1. Rahul Bansal Avatar

      Sorry. I never developed any memcache related codes. We use memcache for WordPress sites through w3-total-cache plugin.

      May be you can post it on –

  7. Jeffrey Avatar

    Hi, really like your posts about wordpress and nginx setup
    how can I make sure I’m using memcache right?

    I install the phpmemcacheadmin, but all the status is 0 ??


    1. Rahul Bansal Avatar

      Run service memcached status
      You should see: * memcached is running

      Also, make sure you have configured WordPress/W3-Total-Cache plugin to use database-cache/object-cache.

Book a strategy call
with our experts

No obligation. Limited slots.

Contact Form Business Enquiry

"*" indicates required fields

Please attach any RFP, project specification, or document that you would like to share.
Drop files here or
Max. file size: 5 GB.
    This field is for validation purposes and should be left unchanged.