[thelist] Generating 'static' php pages with php

Tony Crockford tonyc at boldfish.co.uk
Sun Dec 15 09:27:01 CST 2002


> I was wondering about using php to generate an include file,
> so as to reduce
> the server load. Has anyone got any good info on this, as
> searching google
> for terms such as 'static, php, update' etc. just seems to
> give me pages
> persuading me to use php!!
>
> Thanks for your help
>
> cheers :Donald

I'm using PHP to generate a whole static site from a MySQl database.
(currently about 4,000 pages)

The method revolves around opening a buffer, doing the page generation
PHP, and then opening a file and writing the buffer to it.

The code involved looks like this:

<?php
	ob_start(); //start the PHP output buffer

		//Do some PHP stuff to make a page then

		//write buffer to file
	$data = ob_get_contents(); //puts the content of the output buffer into
the $data variable
	$filename="make up your filename here - you can use PHP variables";
	$fp = fopen ("$filename", "w"); //see the PHP manual for options
	fwrite($fp, $data);
	fclose($fp);
	ob_end_clean();
?>

It took me a while to work out what I wanted to do, but once you get to
grips with it PHP churns out pages quite happily.

It's worth setting the script timelimit to longer than the default (once
you work out how long your script should take) - use: set_time_limit()


HTH

Tony




More information about the thelist mailing list