WHAT'S IN THIS CHAPTER?
Using eAccelerator and APC for opcode and user caching
Using memcached in PHP
Using memcached in MySQL
Methods for maintaining cache and database integrity
A PHP web application's ability to display information — data from a database — is one of its most crucial, core functions. The speed at which this data is retrieved from the database is made manifest to the end user as overall site performance. So, whichever way you can, you try to make your database calls as efficient as possible. This includes trying to get as much information as possible in as few queries as possible, yet ensuring your queries perform optimally.
However, as your web site or web application realizes increased traffic, your database's performance soon becomes a bottleneck and much of what is being continually displayed requires a huge number of queries against the database, causing your database to reach read capacity. This is where you want to employ caching to temporarily cache data that is repetitively needed to provide common data for your web application.
For instance, imagine a popular blog web site. This blog would contain a listing of blog entries composed of a title, the first paragraph of the blog entry, a link to the entire post body, a date, and even a summary of the comment count. Without caching, you would have to run a query against the database for every page display to obtain a listing of blog entries from at least a blog table. ...