Re: how to generate static html pages from dynamic php pages

From: Date: Thu, 09 May 2002 00:15:13 +0000
Subject: Re: how to generate static html pages from dynamic php pages
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-96727@lists.php.net to get a copy of this message
Aha! Philip, thanks -- I think the article is on this page -- I also found this in the Apache documentation: Best, Nicole On-the-fly Content-Regeneration Description: Here comes a really esoteric feature: Dynamically generated but statically served pages, i.e. pages should be delivered as pure 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 served unless one (or a cronjob) removes the static contents. Then the contents gets refreshed.Solution: This is done via the following ruleset: RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^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). Philip Olson wrote:
See this related link: Q "How can I pass variables to a script in the url
    like /script/var1/var2?"
http://www.faqts.com/knowledge_base/view.phtml/aid/124 Includes tutorials for doing it in PHP, mod_rewrite and/or mod_mime. Regards, Philip Olson On Wed, 8 May 2002, Nicole Lallande wrote:
Thanks John - interesting concept - since the pages are being generated from a database they would always be current. Of course I should probably have some 'last update' checking before it runs -- otherwise I could see this impacting server performance? As to the second concept -- you can do this using apache rewrite rules -- I remember seeing an article about it a year ago and unfortunately lost the link to the article. <sigh> Anyone remember this article? Best regards, Nicole 1LT John W. Holmes wrote:
Use output buffering. You just start a buffer, run your script as normal, and at the end, copy the buffer to a variable and write it to a file. Then clear the buffer and move on to the next one. Good thing is that you really don't have to modify your code at all. www.php.net/ob_start One really neat thing I learned from a slide show on php.net... you can have your links be to static urls like www.domain.com/products/1234 Since there is no 1234/ directory to begin with, you'll get a 404 error. So modify your 404 page to look in your database and see if there is a product 1234. If there is, generate the data for the page and actually write a static page to 1234/index.html and redirect the user back to it. This way, the next time someone looks at product 1234, they'll get the static page. And all you have to do to update the static page is delete it. It'll be automatically created the next time someone looks at it. You could even have a cron job that goes in and deletes any files that are over an hour/day/week/ old, etc, to keep things up to date and cleaned up. Also, these static links will be easily searched by search engines, whereas ones with query_strings will not (usually). I just though this was an awesome concept. I haven't had an application that required it yet, unfortunately... ---John Holmes... ----- Original Message ----- From: "Nicole Lallande" <nicole@nmlconsulting.com> To: <php-general@lists.php.net> Sent: Wednesday, May 08, 2002 4:50 PM Subject: [PHP] how to generate static html pages from dynamic php pages
I have a site that is generated dynamically from a database. for the sake of search engine indexing I would like to have the site replicated in static html pages every time the database records a change. My idea is to add this function to the administrative part of the site and save the pages as html at that time. Can anyone point me in a direction to start? Any scripts/existing functions? TIA, Nicole -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- ######################## Nicole Lallande nicole@nmlconsulting.com 760.753.6766 ######################## -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- ######################## Nicole Lallande nicole@nmlconsulting.com 760.753.6766 ########################

« previous php.general (#96727) next »