Although there are many methods, they are simple and easy to use. I think it is easier to first judge the difference between the generation time of the generated home page file and the existing time. If a certain value is met, start generating it. Without further ado, let’s get started!
Before we start, let’s mention three functions: "ob_start(), ob_end_clean(), ob_get_contents()"
ob_start(): It opens the buffer, which means you The contents of the static files that need to be generated are cached here;
ob_get_contents(): reads the content in the buffer, the code is below as an example;
ob_end_clean(): This is more important, only after using this function , the content in the buffer will be read; copy the content to the clipboard code:
Copy code The code is as follows:
if(file_exists("./index.htm"))//Check whether the static index.htm file exists
{
$time=time(); //If the file modification time is different from the current time? Directly direct to htm file, otherwise regenerate htm
if($time-filemtime("./index.htm")< 600)
{
header("Location:classhtml/main.htm") ; }
}
//Add ob_start() at the beginning; CHINAZ
//The homepage content is your dynamic part
// 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 "Generating HTML completed!";
Example code:
Copy code The code is as follows:
ob_start();
?>
$cacheStr=ob_get_contents();
$handle=fopen("jb51.html","w");
fwrite($ handle, $cacheStr);
ob_clean();
?>
http://www.bkjia.com/PHPjc/323068.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323068.htmlTechArticleAlthough there are many methods, they are simple and easy to use. I think it is better to first determine the generation time of the generated homepage file. The difference between the current time and the current time, if a certain value is met, start...