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(): opens the buffer, which is to cache the content of the static file you need to generate here;
ob_get_contents(): reads the contents in the buffer. The following code is 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:
if(file_exists("./index.htm"))//see static Does the index.htm file exist?
{
$time=time(); //If the file modification time is different from the current time?, direct to the htm file, otherwise regenerate the htm
if($time-filemtime("./index.htm")< 600)
{
header("Location:classhtml/main.htm"); }
}
//Add ob_start() at the beginning; CHINAZ
//The home page 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!";