Memcache Installation

What is Memcached?

Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

So to faster your application its needed to use the memcache at your application. Lets proceed the main goal for my post.
Lets Install PHP5 Memcache Extension Module for Ubuntu (note: you must have memcached installed prior to installing this extension module. refer to prerequisite install below):

Follow the following steps to install memcache successfully.

  • Install g++ if you haven’t already.
  • sudo apt-get install make g++
  • Prerequisite Install
  • # Download & install libevent (memcached dependency)
    # Run the command at CMD
    # Extract the archieve file
    tar xfz libevent-1.4.8-stable.tar.gz
    # Enter the directory
    cd libevent-1.4.8-stable
    # Then install by run following command
    ./configure && make && sudo make install
  • Create a symlink to libevent
  • # Run command to symlink
    sudo ln -s /usr/local/lib/ /usr/lib
  • Download & install memcached
  • # Run the following command in CMD
    # Download memcache latest version
    # Extract the archive file
    tar xfz memcached-1.2.6.tar.gz
    cd memcached-1.2.6
    ./configure && make && sudo make install
  • Run the Memcache as a daemon
  • # Run memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port)
    memcached -d -m 1024 -u root -l -p 11211
  • PHP5-Memcache Install
  • # Download the extension module
    apt-get install php5-memcache
    #Edit /etc/php5/conf.d/memcache.ini and uncomment the following line by removing the semi-colon
    # Restart your apache server
    /etc/init.d/apache2 restart
  • Example code to Test Memcache Install
  • <?php
    $memcache = new Memcache;
    $memcache->connect('localhost', 11211) or die ("Could not connect");
    $version = $memcache->getVersion();
    echo "Server's version: ".$version."<br/>\n";
    $tmp_object = new stdClass;
    $tmp_object->str_attr = 'test';
    $tmp_object->int_attr = 123;
    $memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
    echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
    $get_result = $memcache->get('key');
    echo "Data from the cache:<br/>\n";

Enjoy the caching benefit. Enjoy!!!!!!

Make Your URL Smart (Part -1)

When we have started any project with any framework then its look odd to see the index.php at URL all time.
So its better to remove the index.php from URL and make URL smart.
I am showing the process to remove index.php for Linux base OS system and for KOHANA frmawork. The procedure for other framework are also same. So you can remove index.php for other framework in same way.

There are FOUR steps to remove index.php from URL.
1. Edit your bootstrap file [bootstrap.php]

  • Change the base URL to located the actual directory to your file system
  • Make its empty string to index_file

Its looks ilke the bellow:

	'base_url'   =&gt; '/restapi/',  // Your base Url
        'index_file' =&gt; '',

2. Then Edit the .htaccess file


3. Run command in shell to enable the write.

	sudo a2enmod  rewrite
	sudo nano /etc/apache2/sites-enabled/000-default

Edit the 000-default file and save

		Allowoverride all

4. Then restart your server

sudo /etc/init.d/apache2 restart

We have done. Now enjoy your smart URL.
In my next post on this category i will try to cover the routing process. Enjoy!!!!