Page 1 of 1

Faster loading using static html

Posted: Mon Aug 03, 2009 10:15 am
by kkonline
Hi,
I am working on a sql-query intensive homepage and have decided to grab the php output to a html and store it for 5 mins and whenever the user writes mysite.com i just display the readily available html file.

Can you help me work on this concept with ideas and suggestions?

Re: Faster loading using static html

Posted: Mon Aug 03, 2009 10:15 am
by jackpf
So basically a cache?

What are you having trouble with?

Btw, a better option may be to make your queries more efficient.

Re: Faster loading using static html

Posted: Mon Aug 03, 2009 10:17 am
by kkonline
basically how to read the php script output into html file maybe every 5 mins for instance

Re: Faster loading using static html

Posted: Mon Aug 03, 2009 10:21 am
by jackpf
Well, you could put

Code: Select all

if(time() > $time_inserted_when_written_for_cache_timeout) return null;
In the cached file.

Then, when you include that file, check if it's value is null. If it is, write a new version. Instead of echoing stuff out, assign it to a variable, and write the variable to the file, then echo the variable.

There are plenty of tutorials on google for writing cache systems with php.