FeaturesWP CloudPricingEE CLIContactMy Account

Features

Team Access & User Permissions

Server Setup & Management

Site Creation & Management

Deployments & Developer Tools

Firewall Protection

Speed & Caching

Backups & Recovery

Logs & Monitoring

Create WP Cloud Sites

All Features

Read Documentation

Install

Installation Guide

FAQ

Roadmap

Explore EE CLI

Resources

Commands

Handbook

Blog

Community

Forum

EasyExperts

Tutorials

Subscribe

Github

CLEAR

Start For Free

separator Tutorials separator PHP separator memcache

Topics

On this page

Installation

Config

Increase Max Memory memcache can use

Move PHP's session storage to memcache

Changes in w3-total-cache plugin

Web-based Stats Viewer for Memcache

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
		

 

Installation of PHP Code Review Tools

PREVIOUS

PHP's Zend Opcache Config & Web Viewer

NEXT


Comments

  1. RavanH Avatar

    RavanH

    October 7, 2013

    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

      Rahul Bansal

      October 7, 2013

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

  2. Guill Avatar

    Guill

    October 7, 2013

    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

      Rahul Bansal

      October 7, 2013

      You may need following as described in http://rtcamp.com/wordpress-nginx/tutorials/php/zend-opcache/

      opcache.revalidate_freq=0
      opcache.consistency_checks=1
      
      1. Guill Avatar

        Guill

        October 9, 2013

        Oups, missed these 2 lines. Thank you Rahul!

  3. Alex Avatar

    Alex

    January 18, 2014

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

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

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

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 18, 2014

      You can leave session related 2 lines commented.

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

  4. DeAndre Johnson Avatar

    DeAndre Johnson

    January 30, 2014

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

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 3, 2014

      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

    ari

    February 26, 2014

    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

      Rahul Bansal

      February 28, 2014

      Thanks for comment. 🙂

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

  6. SID Avatar

    SID

    February 27, 2014

    Hello!
    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

      Rahul Bansal

      February 28, 2014

      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 – http://stackoverflow.com/

  7. Jeffrey Avatar

    Jeffrey

    February 28, 2014

    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 ??

    tks

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 28, 2014

      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.

Features

Useful Links

Product

Other Products

Subscribe for curated product updates, tips, and announcements.

"*" indicates required fields

Phone

This field is for validation purposes and should be left unchanged.

Email*

SIGN ME UP

Δ


© rtCamp, since 2009. All rights reserved.

Powered by