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

From: Date: Thu, 09 May 2002 15:32:31 +0000
Subject: Re: 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-96822@lists.php.net to get a copy of this message
To actually set the status, and yes it does override the Apache one, you can use something like this: header('Status: 404 Not Found'); This will send a 404 from any old PHP script, for example. > So, if I begin with a completely empty file cache, only the pages that > receive traffic will be generated, and then only once. My cache is > generated dynamically, based completely on what pages receive hits. > > I don't have any schedule setup like you do to remove the > previously-generated files, but if I did, it would work just the same as > your site does. > > So, I suppose we're talking about the same things, just with two > different methods. I prefer mine, since I don't have to worry about > sending the right HTTP headers, but that's just me. Not quite. In your case you have extra dynamic logic and an extra stat since you have to run PHP code on every request to determine whether to serve up the static data or not. The beauty behind the ErrorDocument 404 approach is that absolutely no dynamic code needs to be run once the static file has been generated. It works like this: Request comes in for /foo/bar.html Apache looks for the file /var/www/doc_root/foo/bar.html and doesn't find it thus triggering a 404 error. In your httpd.conf you have this: ErrorDocument 404 /script.php Therefore, instead of Apache sending a 404 to the client, it runs script.php. In script.php you look at $REQUEST_URI and pick out the /foo/bar.html and use that to determine what data to fetch from the database. In my weather reports example, this might be a country code and a city name or something similar. Once you have fetched this information from the db you write it to /var/www/doc_root/foo/bar.html and you also serve it up directly for this request, remembering to do a Header('Status: 200 OK') before sending the data. Now, the next request for /foo/bar.html will again cause Apache to look for /var/www/doc_root/foo/bar.html and hocus-pokus-shazzam, the file exists and is served up statically without any extra code needing to be executed. -Rasmus

« previous php.general (#96822) next »