10 baby steps to install Memcached Server and access it with PHP


Thinking of implementing caching for your php application , you are at a right place. Just in 10 simple (copy and paste) steps you can install and access Memcached Server.

Step1: Install libevent ,libmemcached and libmemcached devel (dependency)

1
2
yum install libevent
yum install libmemcached libmemcached-devel
.

Step 2: Install Memcached Server

1
yum install memcached
.

Step 3: Start Memcached server

1
memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody

(d = daemon, m = memory, u = user, l = IP to listen to, p = port)

.

Step 4: Check your memcached server is running successfully

1
ps -eaf | grep memcached
.

Step 5: Connect Memcached server via telnet

1
telnet 127.0.0.1 11211
.

Step 6: Check current status of Memcached Server on telnet prompt

1
stats
.

Step 7: Exit telnet

1
quit
.

Step 8: Install PHP client to access Memcached Server

1
pecl install memcache

It will make “memcache.so”, you have to just put it on your /etc/php.ini file.

.

Step 9: Restart your apache server

1
service httpd restart
.

Step 10: Open your favorite editor to type below code and execute it, it will cache your data into Memcached server and access it back for you

1
2
3
4
5
6
7
8
9
10
11
12
<?php
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect"); //connect to memcached server
 
$mydata = "i want to cache this line"; //your cacheble data
 
$memcache->set('key', $mydata, false, 100); //add it to memcached server
 
$get_result = $memcache->get('key'); //retrieve your data
 
var_dump($get_result); //show it
?>
.

Hurray!! All done!
Enjoy Caching with Memcached.
Cheers!

Recently Published

»

How to scroll to the top of a webpage using jQuery ?

If you are looking for an extraordinary method of smoothly scrolling ...

»

11 sources to gain perfect knowledge of html5 semantic tags

1. Html5tuts Html5tuts is a site dedicated to HTML5. Feel free to ...

»

How to move an element into another parent element using jQuery?

An important piece to the puzzle when coding with jQuery is that how ...

»

10 optionally Good WordPress Typography Plugins You could Opt For

It is not necessary that the person will follow the standard guide ...

»

8 creative 3d slider wordpress themes to keep your blog active

1. Display Display is a WordPress Theme best used for Portfolio and ...

»

11 quick remote screen sharing apps worth trying

1. Join Me Easy to start, easy to join, easy to manage, join.me takes ...

»

9 perfectly adsense optimized seo friendly responsive magazine wordpress themes

1. Simple Life SIMPLE LIFE is a WordPress responsive theme with a ...

»

9 out of the box jquery plugins not to miss

1. Hatchshow Hatchshow is a typesetting plugin for jQuery that ...

»

10 fresh libraries and web apps you can’t afford to miss

1. Pagekit Pagekit gives you the tools to create beautiful websites. ...