• Stars
    star
    228
  • Rank 174,780 (Top 4 %)
  • Language
    PHP
  • Created over 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Build Status

Overview

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.

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:

```bash

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.
  1. Start the Memcached daemon:

service memcached restart ```

  1. Verify that Memcached is installed and running.

    1. From your server, telnet into the Memcached server

telnet localhost 11211 ```

	You should see output like:

	```bash

Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. ```

1. Type `version` into the Telnet prompt. If Memcached is installed and running, you should see something like:

	```bash

VERSION 1.4.14 (Ubuntu) ```

1. Exit Telnet by typing `ctrl` + `]`, hitting `enter`, then typing `quit` and pressing `enter`.
  1. 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:

```bash

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.
  1. 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 ```

1. Type the following in the interactive shell:

	```bash

php > $m = new Memcached(); php > $m->addServer( '127.0.0.1', 11211 ); php > $m->set( 'foo', 100 ); php > echo $m->get( 'foo' ) . "\n"; ```

1. 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.
  1. 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.

  2. 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
        )
    );
  3. To test the WordPress object cache setup, add the following code as an MU plugin:

    <?php
    $key   = 'dummy';
    $value = '100';
    
    $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.

Authors

  • Zack Tollman
  • 10up

More Repositories

1

backbone-wordpress-theme

A stripped down example of a WordPress theme that utilizes Backbone.js
PHP
137
star
2

ostrichcize

A WordPress plugin to hide PHP errors for specified plugins or themes
PHP
26
star
3

wordpress-https-mixed-content-detector

Monitor a WordPress site served over TLS for mixed content warnings
PHP
23
star
4

a-fresher-cache

Get a fresher cache with a dash of "A Fresher Cache" for absolutely no cash.
PHP
14
star
5

debug-bar-cron

Debug Bar Cron adds a new panel to Debug Bar that displays information about WP scheduled events.
PHP
14
star
6

wordpress-development-course

JavaScript
14
star
7

report-only-capture

Useful scripts for testing the wide array of CSP reports
JavaScript
11
star
8

custom-taxonomy-sort

Custom Taxonomy Sort allows you to explicitly control the sort order of all taxonomy terms.
PHP
10
star
9

csp-report-norm

Normalize Content Security Policy report payloads
JavaScript
8
star
10

diffie-hellman-key-exchange-demo

Materials for presenting a live demo of Diffie Hellman key exchange principles
7
star
11

kses-cases

A test of WordPress kses performance
PHP
6
star
12

ssl-nginx-starter

A sample configuration for SSL and Nginx
JavaScript
6
star
13

caching-for-coders

JavaScript
6
star
14

wcchi-2014

Slide for WCCHI talk on Page Load Time
4
star
15

wp-page-cache

PHP
4
star
16

wphttp

PHP
4
star
17

wordpress-plugin-repository-search-alfred-extension

Searches the WordPress plugin repository for information about plugins
PHP
3
star
18

cookbook-wordpress

A Chef Cookbook for WordPress
Ruby
2
star
19

Quick-Edit-for-Taxonomy-Terms

A primer for adding quick edit for use on the taxonomy term pages
PHP
2
star
20

hither-and-thither

My vivaciously viable Vagrantfile (and related accouterments).
1
star
21

theres-a-function-for-that

JavaScript
1
star
22

wcyvr-2013

Slides from "Towards a Partial Page Templating System in WordPress" talk given at WCYVR 2013
JavaScript
1
star
23

alexa-traffic

An Amazon Echo command built for AWS Lambda that gives you traffic information.
JavaScript
1
star
24

bracket

Keep score of NHL playoff picks
JavaScript
1
star
25

report-only

An application to handle Content Security Policy reports
Shell
1
star
26

screts-lated-posts

A stupid plugin to demonstrate common WordPress development errors.
PHP
1
star
27

report-only-api

JavaScript
1
star