Home >Backend Development >PHP Tutorial >http://67.220.92.14/forum/inde PHP automatically generates static HTML implementation code at regular intervals
However, scheduled generation has some limitations. If you have an independent server, you can set up scheduled tasks on the server, but if you use a virtual host, it will be difficult. Although there are many methods, it is simple and easy to use. I think it is easier to first judge the difference between the generation time of the generated homepage file and the existing time. If a certain value is met, start generating it. Not much to say. Let’s get started!
Found online , remember it. Practice has proven that it is available.
Copy the code The code is as follows:
$nowtime=time();
$pastsec = $nowtime – $_GET["t"];
if($pastsec<60)
{
exit; //Updated once every minute, the time can be adjusted by yourself
}
ob_start(); //Open the buffer
include("index.php");
$content = ob_get_contents(); //Get the buffer The content
$content .= “n”; //Add the code to call the update program
file_put_contents ("index.html",$content);
if (!function_exists("file_put_contents"))
{
function file_put_contents($fn,$fs)
{
$fp=fopen($fn,"w+");
fputs($fp,$fs);
fclose($fp);
}
}
Copy the code The code is as follows:
ob_start(): opens the buffer, which is to cache the content of the static file you need to generate here;
ob_get_contents(): reads To read out the content 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 out;
The above introduces the implementation code of http://67.220.92.14/forum/inde PHP automatically generates static HTML at regular intervals, including the content of http://67.220.92.14/forum/inde. I hope that friends who are interested in PHP tutorials Helps.