Archive for the ‘ memcache ’ Category

Only 10 easy steps to install Memcached Server and access it with PHP


Running You First Application using Memcached Server  thats good you are in right place ———

memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load.

memcached is meant to work in concert with something like the MySQL query cache, not replace it. The two implementations excel at vastly different things: memcached is an object cache, while MySQL provides a query cache.

memcached is extremely fast. It uses libevent, which provides a mechanism to execute a callback function when a specific event occurs on a file descriptor, to scale to any number of open connections. On a modern Linux system memcached utilizes epoll, is completely non-blocking for network I/O, ensures memory never gets fragmented, and uses its own slab allocator and hash table to achieve 0(1) virtual memory allocation.

Memcache consists of two parts; a server library which runs the caching daemon and a client library which allows PHP to interact with the server. The server library is called memcached and it depends on the libevent library, so the first step in the installation process is getting a recent copy of libevent.

Hi this time i am introducing cahching using memchache Server with some easy steps—

***** Remember for ubuntu users if any command does not support or running on command line then goto

System->Administration->Synaptic Package Manager and search by the package name and install

Step1: Install libevent

on fedora


yum install libevent

yum install libmemcached libmemcached-devel

or on ubuntu


sudo apt-get install libevent

sudo apt-get libmemcached libmemcached-devel

Step 2: Install Memcached Server

on fedora


yum install memcached

or on ubuntu


sudo apt-get 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

Testing the memcached daemon with telnet

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

if do not have pear install then first intall pear package —-

on fedora

</pre>
yum <em>install php</em>-<em>pear </em>(if pear is already this command is not necessary)
<pre>

on ubuntu


sudo apt-get install php-pear  (if pear is already this command is not necessary)

then

pecl install memcache

or

sudo pecl install memcache

It will make “memcache.so”,

you have add a line


extension=memcache.so

on your

/etc/php.ini

or

sudo gedit /etc/php5/apache2/php.ini

file

Step 9: Restart your apache server

on fedora


service httpd restart

or on ubuntu


sudo /etc/init.d/apache2 restart

Check your php info

create a file info.php on your local server and write

</pre>
echo phpinfo();
<pre>

then run on the browser you will find ————-

http://localhost/info.php

Memcache Image

Memcache Image

Step 10: Open your favorite editor to write the following 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 = "Chache me Ruzdi"; //string to be cached

$memcache->set('ruzdi', $mydata, false, 100); //add the data to memcached server

$cacheData = $memcache->get('ruzdi'); //retrieve your data from memcache server

var_dump($cacheData); //dump you data which is retrived from memcached server

?>

Cheers …….

This is written with the help of following site——–

link1

link2

link3