php-speed.thumbnail

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