So you have written a PHP web application which is being used heavily enough that it needs to be optimized. Good for you!
Memcached is just the tool for you. It is very easy to install and use and it will drastically speed up most PHP code that can be optimized with caching.
Caching simply means taking a piece of data that can be serialized (an SQL query for example) which is resource intensive and does not change extremely often, and storing the resulting data (as opposed to the query) in memory. Any time a matching query is attempted, the result does not need to be fetched from the database and is instead served directly from memory, drastically reducing the load on the server and latency for the resulting query data to be returned. We will cover a couple ways to avoid returning stale data later in this article.
Exactly what can be optimized with caching is a topic unto itself which I will not delve deeply into here. In general, any heavily used PHP code should at least be benchmarked (both before and after enabling memcached) to see exactly how much it will speed up your code.
I will say that I have seen drastic performance improvement with SQL query intensive code such as social network sites, forums, etc. If your code makes many SQL queries (and let’s face it, what dynamic website doesn’t?), then it is definitely worth trying memcache to see what kind of gains you can achieve. Next, we will see how easy it is to install and use memcached…

