PHP to generate regular HTML home page

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags difference file home page host html index it is network

In order to improve the speed of the site visit, we often generate a static way to achieve, this really did a lot of speed up the site visits.But the timing generated by some limitations, if you have a separate server can be set on the server plan Task, but if it is using the virtual host may not be easy.Although a lot of ways.But it is easy to use, I think it is still the first judgment of the generated home page file generation time and the difference between the existing time, If you meet a certain value to start generating this method is more easy. No more to say.

Before you begin, mention three functions: "ob_start (), ob_end_clean (), ob_get_contents ()"

ob_start (): is to open the buffer is to cache the contents of the static file you need to generate here;
ob_get_contents (): read the contents of the buffer, the following code example;
ob_end_clean (): This is more important, only the use of this function, the contents of the buffer will be read out;

The following is quoted content:

if (file_exists ("./index.htm")) / / See static index.htm file exists
$ time = time ();

// File modification time and the current time difference ?, Directly to htm file, or regenerate htm
if ($ time-filemtime ("./index.htm") <600)
header ("Location: classhtml / main.htm");


// add ob_start () to your beginning;
ob_start ();

// Home 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 (write file error);
// echo "Generate HTML completed!";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: