Forum Moderators: phranque
Thanks,
Jason
On-the-fly Content-Regeneration
Problem Description:
Here comes a really esoteric feature: Dynamically generated but statically served pages, i.e. pages should be delivered as pur static pages (read from the filesystem and just passed through), but they have to be generated dynamically by the webserver if missing. This way you can have CGI-generated pages which are statically unless one (or a cronjob) removes the static contents. Then the contents gets refreshed.
Problem Solution:
This is done via the following ruleset:
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond ^page\.html$ page.cgi [T=application/x-httpd-cgi,L]
Here a request to page.html leads to a internal run of a corresponding page.cgi if page.html is still missing or has filesize null. The trick here is that page.cgi is a usual CGI script which (additionally to its STDOUT) writes its output to the file page.html. Once it was run, the server sends out the data of page.html. When the webmaster wants to force a refresh the contents, he just removes page.html (usually done by a cronjob
Yeah, this can absolutely be done in php. One method would be to cache the entire page (by default, php writes stuff to the client ASAP). At the end of the code execution, you can then write the cache to a file and then write it to the client.
For more info, see the php website. You're looking at
ob_start() ob_getcontents() ob_end_flush()