Welcome to the Linux community forum and interact with 2 million technical staff. We know that accessing dynamic pages is real-time reading data from servers. When there are more and more visitors, the speed will be slow, the generated static pages are not only fast, but also friendly to SEO search engines. Few
Welcome to the Linux community forum and interact with 2 million technical staff> as we know, accessing dynamic pages reads data from servers in real time. When there are more and more visitors, the speed will be slow, the generated static pages are not only fast, but also friendly to SEO search engines. Few
Welcome to the Linux community forum and interact with 2 million technicians>
We know that accessing dynamic pages is to read data from the server in real time. When there are more and more visitors, the speed will be slow, and the generated static pages will not only solve the server pressure problem, it is also very friendly for SEO search engines.
Few people use dynamic and direct data reading. Currently, static html is basically used on webpages. the homepage of a website can be said to be the most frequently accessed page, and of course the most frequently updated page, so how to ensure that the home page is a static html file and can be updated in a timely manner becomes a problem.
This problem occurs when updating the summer article system. How to trigger the user's automatic homepage update? First, let's take a look at the source. If you only want to update the homepage as static html, it is very simple, use the file_put_contents () function of the php file operation to open the home page for reading, and use the function of the php file operation to write data, you can directly generate a static html file, which is performed in the background, however, the disadvantage is that the user cannot be triggered to generate a static homepage.
Next, let's clarify one idea. First, a static page is generated. How can we automatically update the homepage? In fact, the automatic update of the homepage is the Judgment time. In the wp system, there is an automatic post setting, for example, the following code: if (format_date (time (), 1)> "20131001 ″) {echo "automatically update code" ;}, 20131001 can be changed to a regular time.
However, I do not want to use the above method to implement it. I need to pay attention to the fact that this homepage is generated by using the access user before each update to trigger the generation of the static homepage. According to the above principle, the code is very simple. It is enough to update the homepage.
$ Nowtime = time ();
$ Pastsec = $ nowtime-$ _ GET ["t"];
If ($ pastsec <30)
{
Exit; // updated once every 30 seconds. The time can be adjusted by yourself.
}
Ob_start (); // open the buffer
Include ("index. php"); // contains the generated file, such as the homepage.
$ Content = ob_get_contents (); // obtain the buffer content.
$ Content. ="