Tuesday, 29 June 2010

How to Install MEMCACHED on ubuntu?

first of all write the following command on command line:

sudo apt-get install memcached
now go to php.ini file and enable memcache.so


following command automatically append php.ini file and write memcache.so

sudo apt-get install php5-memcache memcached

now check memcached is running or not?


/etc/init.d/memcached status

/etc/init.d/memcached start

To check wether 11211 port is enable or not with
telnet 127.0.01 11211

Now run the memcached script on server:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        // put your code here
        $cache = new Memcache();

        $user_key = 12345;

    /** Look in cache, if not found, set object (misses null) **/
    if (!$user = $cache->get($user_key)) {
       * Set object with expire of 1 hour and no compression
      $value = array(34,56,34,23,23,124,65,767,34,76576,99);
      $cache->set($user_key, $value, NULL, 6000);
      $user = $value;
      echo "In";
            $tVar = $cache->get($user_key);
        echo '<PRE>';
        echo "Out";

This script will first time enter in if condition and second time in else condition.... if it does then your memcached is working fine else there is some error.


No comments:

Post a Comment