Talk about some experiences that generate static pages

xiaoxiao2021-03-06  39

The generation of static pages generally has such a few ideas. 1. During the process of writing. Do not use the direct output statement. When all outputs are connected to the output string, after the output is complete. Write the output string content directly into the file 2. Written in normal ways. Capture the output by the OB function group. The output is then written to the file 3. When using a template class, the output is obtained with the method of GET / FETCH. And write to the file. There are two methods in the specific implementation. When you add a record, you can generate the target HTML page directly, and the front call connection directly points to the generated HTML page. This method is the highest in program efficiency. The server load is light, but since the generated pure static page, once the page style has changed, all content pages must be regenerated. So the application in actual use is generally not too much. More is the use of clients such as JS, SSI, XML / XSL, and only save data in the generated static file, does not involve styles, so that speed and maintenance balance can be achieved, but it is complex relative to the front and backbound procedures (application) When this method, since the content is pure static, it can be used with pure static Apache, which is compiled. The front access link points to the PHP program, and the PHP program first checks if there is a corresponding static file. If the static file does not exist. Then generate and redirect to this file, otherwise redirect directly. This method is actually used in conjunction with the URL_rewrite functionality in Apache. Will be in the form of HTML of the PHP file address, which is conducive to the search engine search. This method is slightly losses in efficiency, but the program structure is simple, easy to adjust, and use is suitable when the amount of access is not very large.

============================================================================================================================================================================================================= I also say it. What is the main purpose of generating a static page? Increase efficiency. Here I use the village as an example to explain my architecture, please note that this architecture is not completely used in the village. ------- ---------------- User read posts, there is a static page ------------ A ------------ - User: Access http://www.phpx.com/happy/static/top92092.htmlapache: file existence. Output file user: Get page ------------------ ----- User read posts, static pages are not generated or deleted ---- b -------------- User: Access http://www.phpx.com/happy/ Static / Top92092.htmlapache: File does not exist. Redirect to 404 handler (httpd.conf 加 EtherDocument 404 /ERRPROCESS.PHP instruction) errProcess.php: Get the page and various variables requested by the user. Do you need to generate a static page The first letter is: TOP, is a page that needs to be generated, call showThread.php (requires the structure to output the page to the variable $ PageContent) Get the content $ PageContent, save $ PageContent to a static file TOP92092.html, Last: a) Header ("location: http://www.phpx.com/happy/static/top92092.html") b) Header ("http / 1.1 200 ok"); after you will directly output $ PAGECONTENT, pay attention to IMG SRC, etc. The location of the relative link !!! User: Get the page or redirect to A operation. ---------------------- User reply ----- -------------------- C ------------- User: Reply to post Top92092.htmlnewreply.php: Delete static files TOP92092. HTML (if user information is also generating static JS, but also delete the user ID.js) data into the library and other conventional operations. Finally: a) Header ("location: http://www.phpx.com/happy/ Static / TOP92092ID.html ") b) or improve NewReply.php After entering the library, call ShowThread.php to get the content $ PageContent, save $ PageContent to Top92092.html, output $ PageContent; but It is recommended to use b) redirect only one static generation point. User: Users get pages or to B operation ---------------------- users published new posts ----------------------- D ------------ User: Publish a new post NewThread.php: (if the user information is also Generate static JS, but also delete user ID.js) data warehousing and other routine operations. Finally: a) Header ("location: http://www.phpx.com/happy/static/top new post id.html ") b) or improve NewThread.php After entering the warehouse, call showthread.php to get the page content $ PageContent, save $ PageContent to Top92092.html, output $ PageContent;

However, in order to unify, it is recommended to use B) redirect only one static generated point. User: Users get pages or to B operation --------------------- Village replaces HTML style -------------------- E --------- Administrator: Delete all file users in the Static directory Access page, page Does not exist, perform B operations (key points: 1 can not directly http://www.phpx.com/happy/top92092.html This other design is problem 2 To pay attention to the file location, such as Happy / Images / A.GIF User Access HAPPY / ShowThread.php When code is written See is right. After generating a static page. The page position turns a happy / static / top92092.html that is the location of the image. Not right. It turned it ../Images/a.gif SoWthread.php is written in There will be something wrong. This will of course bring some problems such as afterwards The location is changed to www.phpx.com/bbs/ The showThread.php code needs to be modified. There are still many similar, such as JavaScript, category. 3 posts require statistical click rate, how to implement it? IMG SRC = / happy / clicked.php? id = 92092 width = 1 height = 1> Change to