Need help with wordpress-pecl-memcached-object-cache?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

215 Stars 103 Forks 143 Commits 29 Opened issues


A WordPress object cache that uses the memcached (not memcache) PECL extension.

Services available


Need anything else?

Contributors list

# 191,962
77 commits
# 161,765
2 commits
# 79,934
1 commit
# 39,171
1 commit

Build Status


This project is a WordPress object cache backend that implements all available methods in the Memcached PECL extension. For a detailed account of how this differs from a Memcache PECL backend (note the inclusion/exclusion of the "d"), read the article I wrote on the topic.


  1. Install the Memcached daemon. Memcached should be available via your favorite package manager in your Linux distribution of choice.

    For Ubuntu and Debian:

    apt-get install memcached

    For CentOS:

    yum install memcached

    Note that you will likely want to review the Memcached configuration directives. To get the best results from Memcached, you will need to configure it for your system and use case.

  2. Start the Memcached daemon:

    service memcached restart
  3. Verify that Memcached is installed and running.

    1. From your server,

      into the Memcached server
      telnet localhost 11211

      You should see output like:

      Connected to localhost.
      Escape character is '^]'.
    2. Type

      into the Telnet prompt. If Memcached is installed and running, you should see something like:
      VERSION 1.4.14 (Ubuntu)
    3. Exit Telnet by typing

      , hitting
      , then typing
      and pressing
  4. Install the Memcached PECL extension on your server. Note that there are two different PHP interfaces for Memcached; one is named PECL Memcache and the other, PECL Memcached. The "d" at the end of Memcached is extremely important in this case. You should be able to install PECL Memcached from your package manager for your Linux distro.

    For Ubuntu and Debian:

    apt-get install php5-memcached

    For CentOS:

    yum install php-pecl-memcached

    Note that if you have a more custom installation of PHP, you might need to take some extra steps to link the PECL Memcached extension to PHP. If you are setting this up using your package manager's version of PHP and PECL Memcached, this should not be necessary. For example, many

    files will exclude packages that begin with
    . You may be able to modify the configuration file as necessary to install this package.
  5. Verify that the Memcached daemon is running and accessible via the PECL Memcached extension in PHP. The easiest way to test this is to run a simple PHP script that connects to Memcached and tries to set and retrieve a value.

    1. Enter PHP's interactive shell:

      php -a
    2. Type the following in the interactive shell:

      php > $m = new Memcached();
      php > $m->addServer( '', 11211 );
      php > $m->set( 'foo', 100 );
      php > echo $m->get( 'foo' ) . "\n";
    3. If that last command returns

      , everything is working! If you get blank output, something is amiss.

      Note that if your PHP configuration does not support the interactive shell, you can use the code above to create a script to execute in the browser. The interactive shell is easier for the verification step as it does not require a functioning web server.

  6. Now that the server dependencies are resolved, the rest of the configuration is in the WordPress application. Take the object-cache.php file and place it in your wp-content folder. For instance, if the root of your WordPress installation is at /srv/www/wordpress, the location of object-cache.php would be /srv/www/wordpress/wp-content/object-cache.php. Please note that object-cache.php is a WordPress drop-in. It is not a regular plugin or an MU plugin. Drop-ins are located directly in the wp-content folder.

  7. Add the following to your wp-config.php file:

    global $memcached_servers;
    $memcached_servers = array(
            '', // Memcached server IP address
            11211        // Memcached server port

    If your Memcached server is located on a different server or port, adjust those values as needed. If you have multiple Memcached instances, add additional servers to the array:

    global $memcached_servers;
    $memcached_servers = array(
  8. To test the WordPress object cache setup, add the following code as an MU plugin:

    $dummy_value = wp_cache_get( $key );

    if ( $value !== $dummy_value ) { echo "The dummy value is not in cache. Adding the value now."; wp_cache_set( $key, $value ); } else { echo "Value is " . $dummy_value . ". The WordPress Memcached Backend is working!"; }

    After adding the code, reload your WordPress site twice. On the second load, you should see a success message printed at the top of the page. Remove the MU plugin after you've verified the setup.


  • Zack Tollman
  • 10up

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.