PHPackages                             humanmade/wordpress-pecl-memcached-object-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. humanmade/wordpress-pecl-memcached-object-cache

ActiveLibrary

humanmade/wordpress-pecl-memcached-object-cache
===============================================

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

v2.1.0(5y ago)40227.8k↑11.6%12[1 PRs](https://github.com/humanmade/wordpress-pecl-memcached-object-cache/pulls)3GPL-2.0-or-laterPHP

Since May 26Pushed 3y ago12 watchersCompare

[ Source](https://github.com/humanmade/wordpress-pecl-memcached-object-cache)[ Packagist](https://packagist.org/packages/humanmade/wordpress-pecl-memcached-object-cache)[ RSS](/packages/humanmade-wordpress-pecl-memcached-object-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (3)

[![Build Status](https://camo.githubusercontent.com/565cc4d0432cdf3aa4e958091f1d85e69d0881591459e3a13bc462632fcad906/68747470733a2f2f7472617669732d63692e6f72672f746f6c6c6d616e7a2f776f726470726573732d6d656d6361636865642d6261636b656e642e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/tollmanz/wordpress-memcached-backend)

❗ A note on plugin status
-------------------------

[](#exclamation-a-note-on-plugin-status)

Since this plugin was last updated, WordPress has introduced a variety of caching API improvements such as [wp\_cache\_get\_multiple](https://make.wordpress.org/core/2020/08/11/introduce-wp_cache_get_multiple/). This plugin has not been updated to take advantage of these new functions, because Human Made now uses Redis for our own caching backend. It should still work, but it will not be as efficient as it could be given the functionality in the latest versions of WordPress.

Overview
--------

[](#overview)

This project is a WordPress object cache backend that implements all available methods in the [Memcached PECL extension](http://www.php.net/manual/en/class.memcached.php). 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](http://tollmanz.com/wordpress-memcached-object-cache/).

Installation
------------

[](#installation)

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](http://serverfault.com/questions/347621/memcache-basic-configuration). 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, `telnet` into the Memcached server

        ```
        telnet localhost 11211
        ```

        You should see output like:

        ```
        Trying 127.0.0.1...
        Connected to localhost.
        Escape character is '^]'.
        ```
    2. Type `version` 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 `ctrl` + `]`, hitting `enter`, then typing `quit` and pressing `enter`.
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 `yum.conf` files will exclude packages that begin with `php`. 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:

        ```
        $m = new Memcached();
        $m->addServer( '127.0.0.1', 11211 );
        $m->set( 'foo', 100 );
        echo $m->get( 'foo' ) . "\n";
        ```
    3. If that last command returns `100`, 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](http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/). 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(
        array(
            '127.0.0.1', // 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(
        array(
            '1.2.3.4',
            11211
        ),
        array(
            '1.2.3.5',
            11211
        )
    );
    ```
8. To test the WordPress object cache setup, add the following code as an MU plugin:

    ```
