Help - Search - Members - Calendar
Full Version: Caching Dynamic Pages
Hostony Board > General Support > PHP/MySQL
motts68
Hi, I stumbled upon some methods of caching for dynamic pages to cut down on processing time, and I've built my own caching system based on these ideas.

Basically, the script looks for a pre-written htm file in a cache directory; if none is found, it writes one out using output buffering and saves it. If one is found however, it will exit() with a file_get_contents() from the cached htm file.

So with all the data from my database (so far), this would result in 927 cached htm files, totaling around 6.3 MB, and would grow over time.

My question then is, which is a better method?

By using the cache, I'd reduce 3-4 queries to my database to about 1, only to compare the modified date of the htm file to my databse content. On the other hand, I have a big mess of htm files, not sure if this increases a seek time or something?
JasonJones
Static content will almost always be faster and less of a strain on a server. I'm guessing you are doing this with some mod_rewrite rules, and an external php file to the do the comparison, if it doesnt exist, writes it out to html, if it does exist, loads it instead?

Do you change site layout much? Headers/footers/news/links etc? If not, writing them out to static is good, if the changes are not very often, you can just go into the dir and delete all the html pages in there when you do make a layout/etc update to make sure that everyone is getting updated content. If you make frequent changes, then it wont be too beneficial at all. If you use a lot of dynamic content on pages (news/random images etc) then the static html will not be good to use either.

Just remember though, now each request has to be rewritten, fed to the php script, then it will process as normal, so you may just be trading one type of load (mysql) for another (php script & static file access)

Jason
motts68
QUOTE(JasonJones @ Oct 29 2004, 11:50 PM)
I'm guessing you are doing this with some mod_rewrite rules, and an external php file to the do the comparison, if it doesnt exist, writes it out to html, if it does exist, loads it instead?

That's pretty much it, the mod_rewrite is solely for search engine compatibility, the php file will always get read. I tried some benchmarking, it seems that using the get_file_contents() function is pretty quick.

The site's fairly static, once the information gets stored in the DB it rarely changes, so it seems the cache would work well, except of course for frequently updated areas.

"Just remember though, now each request has to be rewritten, fed to the php script, then it will process as normal, so you may just be trading one type of load (mysql) for another (php script & static file access)"

Yeah that's pretty much my main question... I suppose some more benchmark tests will show the better route to take. The only other way I've seen it done is processing through the 404 error page, which seems a bit messy to me, clogging up the error logs.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.
IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here