I'm a Drupal PHP/MySQL web developer, living and working in Seattle, WA.
My professional interests are optimization, MySQL, front-end usability, efficient coding, and making Drupal do cool things.
How fast do your dynamic PHP/MySQL pages load? Answer: not fast enough. A truly optimized website should serve pages instantaneously to its visitors. There should be no lag time, even 200 milliseconds of server-side script execution time should be considered a burden worth removing.
The keyword for performance is "caching." By taking the load off the processor and database, a website can easily handle hundreds of thousands of visitors. Many frameworks offers some sort of caching method that stores the final rendered HTML. This is easy to implement for anonymous users, but what about logged-in users?
Every millisecond counts when it comes to performing page requests--not only are cached pages served faster to the user, but it frees up services/memory faster on the server, giving more bang for your buck. This is important not only on high-volume websites, but when you're on a hosting plan that doesn't give you gig upon gigs of memory or high-performance CPU processing power.
The modular nature of Drupal and its excellent API makes it rather straightforward to implement this type of caching. Other frameworks may prove more difficult. The Authcache module can use a number of different caching engines, such as APC, memcached, or even static files. I've found that APC offers the fastest retrieval times, allowing pages to be served in under 1 millisecond!
Implementing Page Caching
The tricky part with page caching is knowing when to retrieve from the cache and when to delete outdated cache. If there is a POST request, such as when a comment is made, then Drupal/PHP will execute the page code normally and invalidate the cache. When we are logged in as an admin, we don't display or save cache pages (because we want our admin links and don't want users to see them). We may also expire our cache after a certain amount of time to always display the most up-to-date content, which is useful on a front page and search result page. Yes, these little details can be a hassle, but the end result is well worth it if your goal is a faster site.
What About Dynamic Content?
Useful Browser Caching Headers
There are also several browser caching techniques that can be used when cached HTML:
header("HTTP/1.1 304 Not Modified");A 304 response does not send any HTML.) This saves on bandwidth and allows the browser to display the page directly from memory without having to redownload and parse the HTML again.
header("Cache-Control: max-age=3600, must-revalidate");). We can this header to cache Ajax responses. This is useful for blocks of user-specific content. For example, if a user votes on a poll, we would want to display the poll results and not the poll vote form. But we don't want to retrieve the poll results on each page view, so we can tell the browser to just cache the block for 10 minutes. A cookie with a timestamp can be used for cache invalidation (e.g., if a user changes their vote, a "vote" cookie containing the unix timestamp is saved, then the Ajax request uses this cookie value when generating the request URL).