The basic principal with any dynamic site to speed up is to reduce the load on the site or in technical words reduce HTTP requests every elements on the web page generates a HTTP request and this HTTP request hits the web server. This could be the front end optimization, the eficiency of the php code optimization or the backend one which is the server site who host the code itself.
How we could possibly optimize the server for this purposes excluding the bandwidth optimization ? The answer is by using cache, and to be specific this is a memory cache that can reduce many http request by supplying the most demanding page from the memory directly. According to wikipedia, cache is explain as “A cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (owing to longer access time) or to compute, compared to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently accessed data can be stored for rapid access.”
Memcache itself was define as a distributed memory object caching system by their site, an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Enough explanation for the background, now give your site a boost with this memcache php5 extention.
Debian is rather outdated on this memcache package, and it needs time to this memcache latest version to hit the apt repositories, so we need to install from source on this. There is a guy wrote the script to download and install this memcache over lenny automatically. The script somehow only a blunt instrument to ease the day and assumes there are no memcached installed from apt repositories before, and will put some startup config file on /etc if you wont’ mind. The script was hosted at here, and I did a small modification for my need you can see here.
After running that script and completed without errors, then the memcached daemon will instantly runs on localhost at port 11211 and ready to serve. I forgot to capture the installation progress, but it should runs good if your lenny is always on good shape by doing updates periodically.
To take advantage this memcache boost, you have to configure your php code to use this memcache server. Here is the example how to achieve that within joomla, wordpress and smf. Many other implementation such as drupal, ruby, python, java or any others API can be found easily on the net.
WordPress memcache plugins setting
smf memcache setting
And here is how to take advantage of memcache within your php code in example :
{code type=PHP}
<?php
$memcache = new Memcache;
$memcache->connect(‘127.0.0.1’, 11211) or die (“Could not connect”); //connect to memcached server
$mydata = “i want to cache this line”; //your cacheble data
$memcache->set(‘key’, $mydata, false, 100); //add it to memcached server
$get_result = $memcache->get(‘key’); //retrieve your data
var_dump($get_result); //show it
?>
{/code}