Forum Moderators: coopster

Message Too Old, No Replies

Cache Dynamic PHP Page Results

How to store a copy of a dynamically created page

         

boxfan

9:17 pm on Nov 27, 2006 (gmt 0)

10+ Year Member



Hello,

I have a page that updates every 3 or 4 minutes. The page is accessed quite frequently and I am looking to build a process that saves a static copy if the data hasn't updated yet. When a user hits the page and the data has updated then I need to create a new static copy.

My question is how do I build an html version of a PHP dynamically created page?

I'm not looking for a PHP cache script like PHP Accelerator or Zend Accelerator. I just need to know how to build a static copy of a page from a dynamic php page. If that makes sense.

Thanks

eelixduppy

9:22 pm on Nov 27, 2006 (gmt 0)



This can be done by writing the HTML code to a file using fwrite [us3.php.net]. Just store the data you want to write in a string and then write it. This process seems a little unnecessary in your case, however.

Anyway, good luck!

BTW, here's all the filesystem functions [us3.php.net] ;)

boxfan

9:47 pm on Nov 27, 2006 (gmt 0)

10+ Year Member



Why do you say, "This process seems a little unnecessary in your case, however."?

Also, I couldn't find it right away but doesn't fwrite have a character or byte limit?

eelixduppy

10:52 pm on Nov 27, 2006 (gmt 0)



>>>Why do you say, "This process seems a little unnecessary in your case, however."?

What I meant was, why aren't you just keeping it dynamic. It depends on what you have being done on the page, but this solution seems unnecessary. Again, it depends. If it's just dynamic text, or pulling info from a db, it seems unnecessary. If you are doing image manipulations each time the page loads (or another server-intensive function), then it would make sense to make a static copy. Either way you can still use cache-control and expire [w3.org] by sending headers [us2.php.net].

>>Also, I couldn't find it right away but doesn't fwrite have a character or byte limit?

Not that I am aware of. You can set your own using the optional parameter (length), though.

boxfan

11:19 pm on Nov 27, 2006 (gmt 0)

10+ Year Member



I get about 12,000 page loads a day from this one page and each page load is using about 25 db queries. I'm trying to reduce the MySQL load on my server as most of the domains I host on the server are MySQL intensive.

Thanks for the info and pointer in the right direction.

eelixduppy

11:24 pm on Nov 27, 2006 (gmt 0)



>>>using about 25 db queries

Make sure to Optimize [dev.mysql.com] your tables and queries to get the most out of them. I'm sure you can reduce the amount of queries if you wanted to. :)

You may also want to take a look at PHP Performance tips. [webmasterworld.com]