I have a pretty complicated index.php now, and I would like to only run it once every hour. What is the best way to achieve this? Some ideas I’ve had
- Put it in APC with
apc_store($page, 60*60*)– I feel this isn’t what APC is for and will probably be doing something bad to the other parts of my site - Save the output to a filesystem somewhere – Then apache needs write access somewhere which might be a pain
- Somehow setup apache to do the caching for me – Is this possible?
I went with a slight variation on Rowlf’s and jamietelin’s
answer.
Create 3 files:
index.html
index.php
index_update.php
And then a cronjob:
So, if someone stumbles on the page after a production push, they will just transparently create a new index.html for you, otherwise, your cronjob will make it every 15 minutes.
Just make sure index.html is writable by your apache server. If that sounds scary, then just make your cronjob run
php index_update.phpas another user with write priviledges to index.html. You won’t have access to all the apache environment though.Hope this helps, comments are welcome.