Memcache PHP Extensions for Memcached Caching Daemon

Memcached (Memcache Daemon) is a caching daemon designed especially for dynamic web applications to decrease database load by storing objects in memory. It is commonly used to speed up dynamic database-driven websites by caching data and objects in server memory to reduce the number of times the data source must be read. Memcached is free and open-source software, licensed under the Revised BSD license. This article will cover PHP extensions which allow you to work with memcached. There are two PHP memcache extensions available from the PHP Extension Community LibraryPHP memcached and PHP memcache.


PHP Memcached vs PHP memcache

memcache vs memcached

These two PHP extensions are not identical. PHP Memcache is older, very stable but has a few limitations. The PHP memcache module utilizes the daemon directly while the PHP memcached module uses the libMemcached client library and also contains some added features. You can compare features and differences between them here.


Installing Memcache Daemon + PHP memcache or PHP memcached

Before selecting a PHP extension be sure to install the memcache daemon:

Centos / Red Hat:

yum install memcached

Ubuntu/ Debian:

apt-get update
apt-get install memcached

After installing Memcached, open the configuration file for Memcached and make any changes:

Centos / Red Hat:

vim /etc/sysconfig/memcached

Ubuntu / Debian:

vim /etc/memcached.conf

Exit and save the configuration file, and then restart Memcached. Remember to set the memcache daemon to start on server boot.

Centos / Red Hat 6:

chkconfig memcached on

CentOS Red Hat 7:

systemctl start memcached
​systemctl enable memcached ​
systemctl status memcached

Ubuntu / Debian:

already started and enabled upon install.


Next lets install a PHP memcache extension. Note: You can search your Linux distribution’s package manager and install from there. I’ve found the following versions to work well…


PHP memcache

tar xf memcache-2.2.7.tgz
cd memcache-2.2.7
make && make install

Then add to your php.ini file:



PHP memcached

Remember to install libmemcached dependency (or for Ubuntu/Debian):

yum install cyrus-sasl-devel zlib-devel gcc-c++
tar -xvf libmemcached-1.0.16.tar.gz
cd libmemcached-1.0.16
./configure --disable-memcached-sasl
make install

Then install PHP Memcached:

tar xf memcached-2.1.0.tgz
cd memcached-2.1.0
make && make install

Then add to your php.ini file:



You will need to connect your PHP application to memcached. For example, using W3 Total Cache with WordPress, memcached module with Drupal, Magento config, etc.

Finally restart memcached and if necessary Apache (and/or Nginx, etc).

If you would like to view stats of hit rate etc you can download memcachephp stats. Which will look something like this…


Published: Aug 29, 2015 | Updated: Feb 11th 2019

Tags: , , , ,