Jun 26 2007

Memcache, Increases the Speed of PHP

php-speed.jpg

Hello Friends,

Memory management is the main problem when you extent your website over a wide range. In php there are a lot of method for speeding up the execution. For a simple case. If you write an algorithm for search a particular keyword from a table, you need to go through all the records for total search results. In this case , you probably use array for saving the result. For a single search it is enough. Think, if your site is viewed by more than 100 users simultaneously, a lot of memory will be loosed for saving the search results as arrays, and you need to execute the database query again and again.

If you can save the intermediate array after the queriying and execution for a particular period of time, you can reuse this array for further queries for a particular period. The php function memcache is using for this purpose. For this you need to install memcahced server on your machine.

Sample php code:

//$a = array(1,2,3,4,5);
$mmc = new Memcache;
$mmc->connect(’127.0.0.1′ ,11211 ) or die (”Could not Connect”);

echo $mmc->getVersion();
$mmc->set(’myarray’,$a, false, 60); // the value will be saved with key myarray for 60 seconds

print_r ( $mmc->get(’myarray’) ) ;

//—Code Ends———————————————

For install memcache using cake use this link:

http://jirikupiainen.com/2007/04/11/memcache-cakephp-cache-memcached-component-helper/

For windows use this link:

http://jehiah.cz/projects/memcached-win32/

For more details use:

http://www.danga.com/memcached/.

Another installation method:

http://pecl.php.net/package/memcache

For user manual

http://www.php.net/memcache

TAGS:

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Sponsors

    Advt on sajithmr.com
    Advt on sajithmr.com
    Itslife Online
    Advt on sajithmr.com

Recent Comments

  • Binny V A: Thanks for the post - love the picture ;-)
  • TheAnand: A lot of people are seeing errors with google video chat….is there any other software which has to be...
  • Alex: Wow, interresting analysis you have done! I’m trying to run GoogleVoiceAndVideoSetup on linux, using...
  • Mella Fitriansyah: Nice plugin, I will try to add this plugin in my blog…
  • Mella Fitriansyah: Nice Info, Sir i will reading your another post success for you

Recent Readers

JOIN MY COMMUNITY!

Recent Posts