12.5. memcached

Unlike the output-caching systems provided by APC, eAccelerator, and JPCache, the memcached system relies on the caching of backend objects for its speed boost. memcached is a distributed memory object caching system created by Danga Interactive, the group responsible for LiveJournal.com. Instead of caching the page output or the compiled PHP opcodes, memcached caches various code objects, most importantly, database result objects and data-model entities.

This caching solution is a bit different than any of the other systems in this chapter—memcached actually requires its own daemon to be running at all times. PHP can then use its memcached function set to access and use the in-memory object cache.

12.5.1. Installing memcached

To install memcached, first grab a copy of the daemon source code from http://www.danga.com/memcached/.

Then extract the tar/gzip archive, and change directory into the newly created folder:

tar -xvzf memcached-1.1.12.tar.gz
cd memcached-1.1.12

Next configure and build the source. If configure reports any missing libraries, such as libevent, download and install those per their individual instructions; then re-run the configure script, and then build memcached.

./configure
make

Then, as root, install the memcache daemon:

make install

The last thing you'll need to do is actually start the daemon. The following command starts the daemon using 128MB of RAM, listening on port 11211 on the IP 127.0.0.1:

/usr/local/bin/memcached -d -m 128 -l 127.0.0.1 ...

Get Professional LAMP: Linux®, Apache, MySQL®, and PHP5 Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.