Mobile app version of vmapp.org
Login or Join
Angie530

: Thoughts on this approach for a news post caching system? 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

@Angie530

Posted in: #Database #Html #Mysql #Php

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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Angie530

1 Comments

Sorted by latest first Latest Oldest Best

 

@Shanna517

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme