Faster loading using static html

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Faster loading using static html

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Faster loading using static html

Post by jackpf »

So basically a cache?

What are you having trouble with?

Btw, a better option may be to make your queries more efficient.
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Re: Faster loading using static html

Post by kkonline »

basically how to read the php script output into html file maybe every 5 mins for instance
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Faster loading using static html

Post 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.
Post Reply