Although a lot of methods, but easy to use, I think it is first to determine the generated first page file generation time and the difference between the existing time, if you meet a value began to generate, this method is easy to compare, not much said, start!
Before you start, mention three functions: "Ob_start (), Ob_end_clean (), ob_get_contents ()"
Ob_start (): is to open the buffer, that is, you need to generate the contents of the static file cache here;
Ob_get_contents (): is read out of the buffer in the content, the following code for example;
Ob_end_clean (): This is more important, only after using this function, the contents of the buffer will be read out; Copy content to Clipboard code:
Copy Code code as follows:
if (File_exists ("./index.htm"))//See whether the static index.htm file exists
{
$time =time (); File modification time and current time difference? If so, direct the HTM file, or regenerate HTM
if ($time-filemtime ("./index.htm") < 600)
{
Header ("location:classhtml/main.htm"); }
}
Add Ob_start () at the beginning of your service; Chinaz
Home content, is your dynamic part of the
Add Ob_end_clean () at the end and output this page to a variable
$temp =ob_get_contents ();
Ob_end_clean ();
Write to File
$FP =fopen ("./index.htm", ' W ');
Fwrite ($FP, $temp) or Die (' Write file error ');
echo "Generate HTML Finish!" ";
Instance code:
Copy Code code as follows:
<?php
Ob_start ();
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv=" Content-type " Content= "text/html; Charset=utf-8 "/>
<title><?php echo" Programming navigation dh.jb51.net ';? ></title>
<body>
<?php echo "dh.jb51.net";? >
</body>
<?php
$cacheStr =ob_get_contents ();
$handle =fopen ("jb51.html", "w");
Fwrite ($handle, $CACHESTR);
Ob_clean ();
?>