Static php pages: True and static

Source: Internet
Author: User

Previously, caching and static pages are accelerating websites. Small websites with low access volumes may not be needed, but if the website size or traffic volume is large, the Static Page and cache will reflect their respective values. Next, let's take a look at the static page Classification.

 

Static Page classification:

1. Follow the form:

1) Real static

2) pseudo-static

2. According to the scope:

1) local static words (jquery, ajax)

2) All static

Static pages can accelerate websites and optimize seo. Because search engines tend to crawl static pages, different search engine seo standards may vary. The following is a link to Baidu search engine optimization.

 

This time I will share with you the real static page technology. This time I will introduce the use of the real static page technology with a simple news management system as an example. The project uses the mvc Architecture.

1. True and static understanding

Real static means to convert the previously accessed jsp, php, and aspx into html, retain the previous page effects and business logic, reduce the pressure on the server, and enable the website to be well indexed. However, there is also a disadvantage in static mode, that is, too many static pages occupy server space, which is not very convenient for maintenance.

Static news management system

1. View Details of a single piece of data as quickly as possible on the list page (for example, View Details of a piece of news in the News list)

If there is no static state, we may choose to upload an ID by clicking the title on the list page, and then query a single piece of data and display it on a page, in this way, we will access the database every time we click the link, so that the pressure on the server will inevitably increase. The recommended practice is to generate the corresponding detailed page every time we add data.

(1) simple background management page

 

(2) Add news

 

 

If (add = $ opper) {$ news = new NewsManagerImpl (); $ title = $ _ POST [title]; $ content = $ _ POST [content]; $ result = $ news-> addNews ($ title, $ content); if ($ result> 0) {// generate static html (used to query a single piece of data) $ fp = fopen (.. /static/news-id-.w.result..html, w); $ ftpl = fopen (.. /tpl/newsDetail. tpl, r); while (! Feof ($ ftpl) {$ row = fgets ($ ftpl); // replace the corresponding position $ row = str_replace ({title}, $ title, $ row ); $ row = str_replace ({content}, $ content, $ row); fwrite ($ fp, $ row);} fclose ($ ftpl); fclose ($ fp ); header (Location :.. /manage/success.html);} exit ();}

Next let's take a look at the newsDetail. tpl template file.

 

 

    


News Title News content
{Title} {Content}

2. Static list page

 

This part of work is actually very simple. It depends on whether you can think about it. For example, we can follow the original practice to modify or delete it, you only need to regularly update the static list page. The update frequency is as needed.

The following is my practice:

 

If (updatecache = $ opper) {$ rowInfo =; $ listInfo =; $ news = new NewsManagerImpl (); $ all = $ news-> getAllNews (); for ($ I = 0; $ I <count ($ all); $ I ++) {$ row = $ all [$ I]; // concatenates list information $ listInfo. =; $ listInfo. ={$ row ['id']}; $ listInfo. ={$ row ['title']}; $ listInfo. = view; // $ listInfo. = Delete; // $ listInfo. = Modify; $ listInfo. =;} // static list page $ listTpl = fopen (.. /tpl/newsList. tpl, r); while (! Feof ($ listTpl) {$ rowInfo. = fgets ($ listTpl);} $ all = str_replace ({newsContent}, $ listInfo, $ rowInfo); $ staticListFp = fopen (.. /static/newsList.html, w); fwrite ($ staticListFp, $ all); fclose ($ listTpl); fclose ($ staticListFp); header (Location :.. /manage/success.html );}

Is it just a simple operation to re-read the data? Finally, I will tell you how many provinces I have written here.

 

 

 

 

In the background, you generally do not need to consider static, because the background shows itself, as long as the performance is not very poor, static is of little significance.

 

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.