Jump to content

Cache html pages from php code?


jggretton

Recommended Posts

Hello all, it's my first php freaks post, so hopefully you can help me out. I'm not a complete php novice, probably about average ~1 year working on and off with php.

I've made a few sites in this time with some simple home-made php cms. As most of these sites are very rarely updated, it seems wasteful to query the database and run lengthly scripts for each and every page request. So I was thinking about making html caches (where appropriate) of my php pages.

My scripts are currently in the form:

[code=php:0]
<? foreach($image as $i){ ?>
    <img src="<? print $i['src'];?>" alt="<? print $i['title']; ?>" ............................ />
<? } ?>
[/code]

So it's not enough to just replace "print ..." with "$output = ...", and then fwrite $output to a file.

Is there a way to instead send the output of the script to a file rather than straight to the browser. This could save me an awful lot of rewriting.

Thank you very much for any help you can give me,

James

PS. I'm planning to change my htaccess rewriting to access the cached html version instead of the php thus ensuring urls don't change!





Link to comment
https://forums.phpfreaks.com/topic/35104-cache-html-pages-from-php-code/
Share on other sites

I could make a seperate script that opens the file from the url using fopen:

[code=php:0]
  $handle = fopen("http://www.mydomain.com/pagetocache.php", "r");
[/code]

And then save this as "/home/.../pagetocache.html" using fwrite() on a new file handle.

But it seems a shame to leave the server to get this info, so I was hoping someone might have a more elegant solution!

Thanks,

James

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.