1

I'm working on a website which uses /news/title-of-news-article--111.html (111 = unique ID of the news article). I was thinking it might be a good idea to have some form of a caching system for the news articles.

Essentially, my idea would be to have a .html version of the news article (i.e. just the news part that's dynamically generated) be created when it was marked live (making it so visitors and search engines can see it). The .php script that displays the content would check to see if a .html file with the news id exists, and would use that instead of querying the database. Of course, if the .html file didn't exists for some reason, it would fall back to querying the database like the site currently does now.

Any issues you guys see with that approach? This is meant more for when a ton of visitors view a news article, since ideally I'd assume grabbing a "static" .html file is better on the server and the database than querying.

1 Answer 1

1

It seems fine, but why put a numeric ID in the filename? The user doesn't need to see that. It just clutters the URL.

Also, there may be other solutions you could explore. For example, databases like MySQL have query caching, which caches frequent queries instead of having to execute the query again and again. This is enabled by default, but you may want to optimize the cache size for your server. And if you use Memcached, then the database server won't even need to be connected to as the data will be cached in local memory.

On a separate note, make sure your web server is using FastCGI. Switching from CGI to FastCGI can literally reduce your server response time by over 50%, making your PHP script essentially as fast as loading a flat file. Any competent web host should already be using it, but if you're not, then this would be priority number one for me. You might also want to use APC, which caches your PHP scripts as byte code and further speeds up response time.

I think caching to flat html files is still a smart move to reduce server load, but be aware of these other optimizations as they can make a big difference as well.

2
  • 1
    The numeric ID is for Google News, IIRC. As for the other solutions, any way to check if those are enabled easily or can be installed locally (maybe via phpinfo()?) --- the website is currently on a shared server so we don't have access to the core stuff. Commented Nov 28, 2010 at 18:42
  • @Shawn Collier: I see. I hadn't heard about that before. I guess that would be the exception to the rule. And, yes, FastCGI will be displayed in phpinfo() under Server API, whereas APC and Memcached will be listed under extensions. Commented Dec 24, 2010 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.