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)

yum install libevent
yum install libmemcached libmemcached-devel
.

Step 2: Install Memcached Server

yum install memcached
.

Step 3: Start Memcached server

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

ps -eaf | grep memcached
.

Step 5: Connect Memcached server via telnet

telnet 127.0.0.1 11211
.

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

stats
.

Step 7: Exit telnet

quit
.

Step 8: Install PHP client to access Memcached Server

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

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

<?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

»

4 flawless WordPress Plugins for Employee Management

Keeping your employee management in check is an important part of ...

»

Kubernetes: Why Today’s Programmers Need to Understand

Launched by three Google engineers, Kubernetes is a container ...

»

Do I Need Endpoint detection and response tools ?

Endpoint detection and response (EDR) tools are designed to add an ...

»

How to Build a Killer Marketing Strategy for your WordPress Blog?

Running a blog over WordPress is seemingly an easy thing to do. The ...

»

5 Signs You Need a New Hosting Company

Web hosting has become cheaper and easier to attain than ever before. ...

»

5 Things to Consider When Designing A Logo For Your Startup

Designing a Logo is essential because it communicates your business. ...

»

What Is Access Control?

Access Control, When running a business, there are dozens of things ...

»

Process Management Solution For a Business

In order to be successful, a company needs to be on the same page and ...

»

5 Metrics You Should Track on Every Blog Post

As a blogger, you may have developed your blog with a variety of blog ...