bachx Posted August 23, 2007 Share Posted August 23, 2007 I want to create a page that updates every 15 minutes only, so that whenever you view that page, you'll view a mirror/image of the last update (not the current data). This is done to reduce the load on the site, as that page contains many queries/etc, so running those queries every time someone view this page will slow the site down. Any ideas how can this be done? Need help ASAP. Quote Link to comment https://forums.phpfreaks.com/topic/66401-creating-a-snapshot-of-the-database/ Share on other sites More sharing options...
Jessica Posted August 23, 2007 Share Posted August 23, 2007 Well, you could make the page static text, and then have a script run with cron every 15 minutes which overwrites that file with the new page. Quote Link to comment https://forums.phpfreaks.com/topic/66401-creating-a-snapshot-of-the-database/#findComment-332342 Share on other sites More sharing options...
bachx Posted August 26, 2007 Author Share Posted August 26, 2007 Well, I wasn't really able to create such a script. I've seen such pages (For example, those that updates the Users Online page every 5 minutes only), I know there is a cron script that runs every 5 minutes, but I couldn't manage to overwrite the file using 'fwrite' since it's not simply a simple string, but a full page with HTML/Javascripts/etc. Any ideas? Would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/66401-creating-a-snapshot-of-the-database/#findComment-334416 Share on other sites More sharing options...
bachx Posted August 26, 2007 Author Share Posted August 26, 2007 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/66401-creating-a-snapshot-of-the-database/#findComment-334532 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 No need to modify the file, recreate it. Make a function with all your html and javascript and whatever and run it with cron: function createFile($text, $file){ $text = echo "<html><head><title>My Site</title></head><body>$text</body></hml>"; $handle = fopen($file, 'w+'); fwrite($handle, $text); fclose($handle); return true; } It is a simple example but surely it can be done even in more complex scenarios. Quote Link to comment https://forums.phpfreaks.com/topic/66401-creating-a-snapshot-of-the-database/#findComment-334536 Share on other sites More sharing options...
Barand Posted August 26, 2007 Share Posted August 26, 2007 At the top of your page script put <?php ob_start(); ?> At the end, after the final /html tag put <?php $pagecontent = ob_get_contents(); // get the contents of the page file_put_contents('mypage.html', $pagecontent); // save to file ob_end_flush(); // output the page ?> When you run the script the rendered contents are saved in mypage.html Quote Link to comment https://forums.phpfreaks.com/topic/66401-creating-a-snapshot-of-the-database/#findComment-334626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.