Memcache – PHP data caching method

 
Memcache – PHP data caching method

Memcache modules are used to cache any type of data in memory to reduce the repetitive database load time.

Memcache and client tools installation steps

1) Install memcache and client tools(PHP) by running the commands
> yum install memcache php-pecl-memcache
> yum install memcached

2) Edit “memcached” file and update the required settings as mentioned below
> vi /etc/sysconfig/memcached

Update it as follows:
PORT=”11211″
USER=”memcached”
# max connection 1024
MAXCONN=”1024″
# set ram size to 1024 – 1GiB
CACHESIZE=”1024″
# listen to loopback ip 127.0.0.1, for network connection use real ip e.g., 10.0.0.4
OPTIONS=”-l 127.0.0.1″

3) Activate the service using
> chkconfig memcached on

4) Start the service using
> service memcached start

5) Allow HTTPD scripts and modules to connect to the network using
> setsebool -P httpd_can_network_connect 1

6) Restart HTTPD service using
> service httpd restart

Tools and dependencies installation part over.

Now the client API integration part. To use memcache with PHP refer http://in1.php.net/manual/en/book.memcache.php

TIPS: This command is useful to show the caching history

> memcached-tool 127.0.0.1:11211 [display/stats/dump]

display – Shows slabs allocations
stats – Shows general statistics
dump – Dumps keys and values

Suriya Prakash
Latest posts by Suriya Prakash (see all)