Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
1. Setting-up RPMForge respository. RPMForge repository (http://dag.wieers.com) is the biggest rpm respository for RHEL, CentOS for all versions. Setup the RPMForge repository as mentionedhere.
2. Install memcached.
Use yum to install memcached
1 |
yum -y install memcached |
As soon as memcached installation completed, edit options for memcached in /etc/sysconfig/memcached to meet your need.
1 |
vi /etc/sysconfig/memcached |
1 2 3 4 5 |
PORT=”11211″ #define on which port to run USER=”nobody” #same as apache user MAXCONN=”1024″ #maximum number of connections allowed CACHESIZE=”64″ #memory used for caching OPTIONS=”" #use for any custom options |
Save the file. All options can be seen by using following command
1 |
memcached -h |
Start memcached
1 2 |
/etc/init.d/memcached start Starting Distributed memory caching (memcached): [ OK ] |
To check the running status of memcached
1 2 |
/etc/init.d/memcached status memcached (pid 6475) is running… |
and
1 2 3 |
netstat -anp | grep 11211 tcp 0 0 :::11211 :::* LISTEN 6475/memcached udp 0 0 0.0.0.0:11211 0.0.0.0:* 6475/memcached |
3. Install PHP Extension.
Download and install latest stable memcache version from PECL.
1 2 3 4 5 6 7 8 |
cd /usr/local/src wget <a class="external free" href="http://pecl.php.net/get/memcache-2.2.7.tgz" rel="nofollow">http://pecl.php.net/get/memcache-2.2.7.tgz</a> tar zxvf memcache-2.2.7.tgz cd memcache-2.2.7 phpize ./configure make make install |
memcache.so will be installed in php modules directory, now enable memcache.so extension in php.ini
To find out your php.ini location, execute following command
1 2 3 |
php -i | grep php.ini Configuration File (php.ini) Path => /usr/local/lib Loaded Configuration File => /usr/local/lib/php.ini |
1 |
vi /usr/local/lib/php.ini |
1 |
extension = “memcache.so” |
Save the file and restart httpd server.
1 |
/etc/init.d/httpd restart |
To check is memcache extension loaded in php, execute following command.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
php -i | grep memcache memcache memcache support => enabled memcache.allow_failover => 1 => 1 memcache.chunk_size => 8192 => 8192 memcache.default_port => 11211 => 11211 memcache.default_timeout_ms => 1000 => 1000 memcache.hash_function => crc32 => crc32 memcache.hash_strategy => standard => standard memcache.max_failover_attempts => 20 => 20 Registered save handlers => files user sqlite memcache PWD => /usr/src/memcache-2.2.7 _SERVER["PWD"] => /usr/src/memcache-2.2.7 _ENV["PWD"] => /usr/src/memcache-2.2.7 |
This information can also be seen using phpinfo().