Saving Resources with phpCache

Databases are spectacular tools -- using one at the back of your Website can give you tremendous power in terms of flexibility and maintenance. A database effectively separates your content from the design, allowing you to edit one without affecting the other. This, coupled with the development of newer scripting languages like PHP and free databases like MySQL, has seen the popularity of database-driven sites increase.

However, even though database-driven Websites offer many benefits over their traditional, static counterparts, there are two major downsides to running a dynamic site. The first is that people tend to use query strings (anything following a "?" in the URL), to pass the correct information to their scripts. This approach can create problems with search engines, however, there are a few solutions to this issue, as discussed in this article: Search Engine-Friendly URLs.

The second problem with a dynamic site is that it can create a high server load, and as your site grows in popularity, it may become slower due to an increase in the number of database queries being performed. In this article we’ll look at a solution to this problem – the implementation of a caching system for your site.

There are different ways to decrease the server load your site generates. Some recommend the use of static rather than dynamic pages, and the periodic running of a script or program that generates the new static page. This approach works -- but what if you still want some elements served dynamically on the page in question?

Well, you could write a script that generates another script periodically. For instance, instead of using a PHP script to generate an HTML file, you could use a PHP script to generate another PHP script. In such a case, the generated script would cause less server overhead than its parent. While this approach might succeed, it may also create more work – you’ll need to write a different script to generate each page that you run using this technique. Also, if you choose to generate HTML pages, and then change your mind later, you might have to wait a month or more to have all your new pages indexed by search engines. And in that time, you could easily lose your results rankings.

Instead, why not use a caching system? This tool allows you to cache parts of your script, such as the database queries, while it keeps other elements completely dynamic. So how do you write a caching system? Well, you don’t need to, because Nathan at 0x00.org has written a great system and released it under the General Public License. This article will teach you how to install and use this script on your own site.