In order to speed up website visits, we often adopt a natural static method, which indeed improves the website visit speed a lot. however, it is inherently limited. if you have an independent server, you can set your plan on the server.
In order to speed up website visits, we often adopt a natural static method, which indeed improves the website visit speed a lot. however, some limitations are inherent in the timing. if you have an independent server, you can set the intended task on the server, but it is hard to do if you are using a virtual host. although there are many methods. however, it is easy to use. I feel that it is easy to determine the difference between the natural time of the home page file and the existing time. not a few words. start!
Before getting started, let's mention three functions: 'OB _ start (), ob_end_clean (), ob_get_contents ()'
Ob_start (): it is used to open the buffer, that is, to cache the content of your natural static file here;
Ob_get_contents (): read the content in the buffer. the following code is used as an example;
Ob_end_clean (): This is more important. only after this function is applied can the content in the buffer be read;
If (file_exists ('./index.htm') // check whether the static index.htm file exists.
{
$ Time = time ();
// Is the file correction time different from the current time? Direct to the htm file. Otherwise, the htm file will be created again.
If ($ time-filemtime ('./index.htm') <600)
{
Header ('Location: classhtml/main.htm ');
}
}
// Participate in ob_start () at your beginning ();
Ob_start ();
// 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 the file
$ Fp = fopen ('./index.htm', 'w ');
Fwrite ($ fp, $ temp) or die ('file writing error ');
// Echo 'HTML is complete by nature! ';