Chris Bruce wrote:
Hi,
I am looking for a way to write to a file what the browser would see (raw html) when viewing a dynamic PHP page. I have numerous include files, MySQL db queries, loops etc. and I want to generate the static result of that file and save it as an html page. I have toyed a little with output buffering to no avail.
Is there an easy way to do this?
Thanks,
Chris
Here's a great article on the subject from the Zend website:
http://www.zend.com/zend/art/scriptcaching.php
It's a little more complex than you would hope but is well thought out.
--Separate directories is set up to hold the php source and the cached html.
--The cached html directory is initially empty.
--An Apache ErrorDocument directive is used to intercept the "404 document not found" error when someone is requesting a page and to redirect it to a single caching script.
--This caching script uses fopen() to open and then read the php script and to write the output to the cached html directory.
Hats off to Zend for publishing this. It competes with their Zend Cache product. From the article:
"If your site contains a few small scripts, you may not need to bother with caching at all. On the other hand, if you rely on complex scripts and fresh data, you should use a much more sophisticated solution, such as the Zend Cache <http://www.zend.com/store/products/zend-cache.php>. But if you are somewhere in between, I hope this article will be of help to you. If you have any comments, please feel free to email me."
(Sorry to take so long to post this. I had remembered reading the article but couldn't find it. Finally thought to do a Google for "404 php cache".)
Hope this helps,
-John
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php