Quantcast
Channel: Control Panel – IPSERVERONE
Viewing all articles
Browse latest Browse all 144

How to install memcached and libmemcached

$
0
0

1. Install memcached from source

Download the latest source from http://memcached.org/

# cd /usr/src
# wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
# tar xvf memcached-1.4.15.tar.gz
# cd memcached-1.4.15
# ./configure -–with-libevent
# make && make install

Please make sure the libevent & libevent-devel packages has been installed before run ./configure

2. Install libmemcached from source

Download the latest source from http://libmemcached.org/libMemcached.html

# wget https://launchpad.net/libmemcached/1.0/1.0.17/+download/libmemcached-1.0.17.tar.gz
# tar xvf libmemcached-1.0.17.tar.gz
# cd libmemcached-1.0.17
# ./configure
# make & make install

3. Start the memcached as daemon process

# memcached -d -u nobody -m 1048 -p 11211 127.0.0.1

To make sure the memcached is automatically running after server has rebooted, run

# vim /etc/rc.d/rc.local
// add this line
memcached -d -u nobody -m 1048 -p 11211 127.0.0.1

4. Install the Memcache PECL Extension for PHP

# pecl install memcache

Add the extension in php.ini

# vim /usr/local/lib/php.ini
// add this line
extension=memcache.so

restart the httpd service

# /etc/init.d/httpd restart

5. Verify the memcached using php and libmemcached

Create new .php file and add the codes as below

<?php
    $memcache = new Memcache;
    $memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1"

    echo "Server's version: " . $memcache->getVersion() . "<br />\n";
 
    $tmp_object = new stdClass;
    $tmp_object->str_attr = "test";
    $tmp_object->int_attr = 123;
 
    $memcache->set("key",$tmp_object,false,10);
    echo "Store data in the cache (data will expire in 10 seconds)<br />\n";
 
    echo "Data from the cache:<br />\n";
    var_dump($memcache->get("key"));
?>

or else, run

# strace -p `pidof memcached`

reference http://goo.gl/Fds40


Viewing all articles
Browse latest Browse all 144

Trending Articles