Home > Backend Development > PHP Tutorial > Simple page buffering technology 1_PHP tutorial

Simple page buffering technology 1_PHP tutorial

WBOY
Release: 2016-07-13 17:28:56
Original
761 people have browsed it

b>Foreword
In fact, calling it technology may not be called a real technology. This is just my own method of page processing, and of course it may be consistent with other people's ideas. But I still want to give it a nice name. So what is page buffering I am referring to here? It means to save the dynamically generated page for next use. This way the next time you access it, you may not need to dynamically generate it. It's like providing a cache. On my site, and perhaps yours as well, I use techniques like templates so that the page the user sees is dynamically generated. But a page that is like this to you may still be like this to others, that is, it will not change for a period of time. Wouldn't it be better if the results generated last time were directly returned to the user who visits next time? The generation time is reduced and the efficiency is higher. I think as the website develops, issues of speed and efficiency still need to be considered. Here I give my implementation, I hope it will be helpful to everyone. It's just an idea, no concrete implementation.
Conditions of use
Is it best to use it on all web pages? I don't think it's necessary, and it's impossible. The reason why it can be buffered is that the content of the next access may be exactly the same as the content of the previous access. So it is not suitable for pages that change frequently. For example, it is not appropriate to display counting information on the page. Also, if your dynamic page is output without first outputting it to a variable, but directly returning it to the user, such as using echo, print, readfile and other outputs, I personally think it is not possible yet. Because the output results cannot be obtained and saved to a file (anyway, I have been thinking about it for a long time and haven't figured out anything that can cut off the output and redirect it to a file). Then the more appropriate processing of dynamic pages is: the output results should be placed in a string. So the usage conditions are:
The page will basically not change
The processing results of dynamic pages can be stored in strings
In this way, it is good to use template classes to process dynamic pages. By setting replaceable variables in the template, and then replacing the variables in the corresponding template according to the actual values, the results can be put into strings for output. This kind of template class processing is very suitable for saving the processed page. Of course, it is also feasible to generate output results through string processing without using template classes. How to do it will not be discussed.
Implementation
As mentioned before, it is not a real implementation, but an idea of ​​implementation.
Processing flow:
According to the access requirements, generate the buffer file name


Check whether the file name exists. If the file does not exist, generate a dynamic page, save the page, and output the result at the same time. End; If it exists, perform step 3
to count the modification time of the file and the modification time of the files related to dynamic page generation
to compare the modification time of the buffer file. 渌take advantage of the 嘘薷氖Benrun浯笨訯怦怦�raise薷薖Benrun洌title峁衡芑dai⑸浠蛑妦法Whattake advantage of the prostitute Mao 4 Xian sedan chair recruitment Step
indicates that the buffer file is the latest, then directly output the buffer file
This is my solution. As for how to save buffer files, you can create a temporary directory or use database processing. If a database is used, the method of determining whether a file is the latest should also be changed. For example, adding a generation time field to the database and comparing this time field with the modification time of other files. Everyone thinks of their own method.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531734.htmlTechArticleb>The preface actually calls it technology, but it may not be said to be a real technology. This is just my own method of page processing, and of course it may be consistent with other people's ideas. But I...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template