However, regular generation has some limitations. If you have an independent server, you can set scheduled tasks on the server. However, if you use a virtual host, it is not easy to do. although there are many methods. however, it is easy to use. I think it is easier to determine the difference between the generation time of the generated homepage file and the existing time. If a value is satisfied, it is easier to generate this method. not much. start!
Remember what I found online. Proven to be available.
Copy codeThe Code is as follows:
<? Php
$ Nowtime = time ();
$ Pastsec = $ nowtime-$ _ GET ["t"];
If ($ pastsec <60)
{
Exit; // update once every 1 minute. The time can be adjusted by yourself.
}
Ob_start (); // open the buffer
Include ("index. php ");
$ Content = ob_get_contents (); // obtain the buffer content.
$ Content. = "n <script language = javascript src =" f5.php? T = ". $ nowtime."> </script> "; // Add the code that calls the update program.
File_put_contents(javasindex.html ", $ content );
If (! Function_exists ("file_put_contents "))
{
Function file_put_contents ($ fn, $ fs)
{
$ Fp = fopen ($ fn, "w + ");
Fputs ($ fp, $ fs );
Fclose ($ fp );
}
}
Below are some explanations:
Before you start, let's mention three functions: "ob_start (), ob_end_clean (), ob_get_contents ()"
Copy codeThe Code is as follows:
Ob_start (): it is used to open the buffer, that is, to cache the content of the static file you need to generate here;
Ob_get_contents (): Read the content in the buffer. The following code is used as an example;
Ob_end_clean (): This is important. Only when this function is used can the content in the buffer be read;
[Code]
If (file_exists ("./index.htm") // check whether the static index.htm file exists.
{
$ Time = time ();
// Is the file modification time different from the current time? Otherwise, the htm file will be generated again.
If ($ time-filemtime ("./index.htm") <600)
{
Header ("Location: classhtml/main.htm ");
}
}
// Add ob_start () to your start ();
Ob_start ();
// The homepage content is your dynamic part
// Add ob_end_clean () to the end and output this page to a variable.
$ Temp = ob_get_contents ();
Ob_end_clean ();
// Write a file
$ Fp = fopen ("./index.htm", 'w ');
Fwrite ($ fp, $ temp) or die ('file writing error ');
// Echo "HTML generation complete! ";
[Html]