PHP Caching
One way to maximize what you get out of your server hardware is via caching. For those unfamiliar with the idea, Wikipedia has a highly technical article, but the basic idea is that once a computationally expensive process has occurred, the results of the process are stored so that subsequent requests for the results can be retrieved quickly. A real life example: you have a few bills to pay, so you add them up and write down the total you owe. Next time you need to find out how much you owe, you look at the piece of paper, rather than adding all the bills up again. Makes sense, eh?
Unfortunately, PHP doesn’t offer any sort of caching functionality in its core, unlike some other middle tier web application servers, ColdFusion being one example. There are some database caching tools that I’m aware of, like Memcached which has an extension for PHP. While database access is generally the major bottleneck in application performance, this approach still requires that PHP interpret and output the entire script requested. What if we could eliminate database access AND PHP interpretation for requests of dynamic pages? Then the entire load of the application would be on the web server to transmit files over HTTP, without any pre-processing. Doesn’t exactly sound like a dynamic app though, does it?
The core value that database driven web applications is that as a database changes, the web application state automatically updates to match the database. Our presentation layer should only need to change when the database changes; querying the database/executing business logic/rendering HTML on every request is just wasted cycles if the data hasn’t changed. A PHP caching system that I envision would have all presentation templates output static HTML files, which are what is actually served to end users. When database updates are made (a user changes account info, a new item is added to a storefront), the impacted static HTML files are overwritten with the new data. It’s easy to imagine outputting flat XML files, which could then be transformed for various display platforms too.
I’m not sure if this would actually result in performance increase, since highly dynamic data would lead to lots of file writing, but I would think that if you’re looking at something like 10 pageviews : 1 database update, you’d see much lower overhead, even compared to a query caching solution. According to Technorati, a number of major sites don’t actually see a high percentage of “participation visits”, so a real world ratio might be much more skewed than 10:1. An actual system would have to be in place to run the definitive tests, of course. Does anyone know of any systems or projects that use this approach? I’d imagine that it/they exist, but I don’t yet know of any.
No comments Jump to comment form | comments rss | trackback uri
Say what?
About this entry
Categories
- App Design (8)
- Blogs (6)
- Business (4)
- Code Philosophy (2)
- Javascript (1)
- Open Source (5)
- PHP (15)
- Thoughts (2)
- Tools (10)
- Usability (3)
- Wordpress (2)
- Zend Framework (9)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>