PHP page static _php static tutorial

Source: Internet
Author: User
The previous cache and now said that the page static is to speed up the site, if the small number of visits to small sites may not be required but if the site size or access is large, then the page static and cache will reflect the value of the next page to understand the static classification

Page-Static classification:

1, in accordance with the form:

1) True static

2) Pseudo-static

2, by Scope:

1) Local static session (JQUERY,AJAX)

2) All static

Page static can speed up the site and SEO optimization, because the search engine is inclined to crawl static pages, for different search engine SEO standards may be different. Below provides a Baidu search engine optimization link

This time to share with you is the page of true static technology, this will be a simple news management system as an example of the use of true static technology, the project uses the MVC architecture to get

A. True static understanding

True static is to make our previous access to the jsp,php,aspx into HTML, retain the previous page effect and business logic, reduce the pressure on the server, so that the site is well included. But the true static also has the disadvantage that is excessive static page occupies the server space, maintenance is not very convenient.

Static news management system at the beginning of the second

1. View the details of a single piece of data by using the list page as quickly as you like (such as viewing the details of a news item through a news list)

If there is no static, our approach may be by clicking on the title of the list page to pass an ID past, then query out a single piece of data to be displayed on a page, so that each time we click on the link to access the database, so that the pressure on the server must become larger, It is advisable to generate the corresponding detail page each time the data is added

(1) Simple Background Management page

(2) How to add News

if (add== $opper) {    $news =new newsmanagerimpl ();    $title =$_post[title];    $content =$_post[content];    $result = $news->addnews ($title, $content);    if ($result >0) {    //generates static HTML (for querying single data)    $fp =fopen (.. /static/news-id-. $result. HTML, w);    $ftpl =fopen (.. /TPL/NEWSDETAIL.TPL, R);        while (!feof ($FTPL)) {    $row =fgets ($FTPL);    Replace the corresponding location    $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 ();}

Let's take a look at Newsdetail.tpl this template file

<title></title>

News Headlines News content
{title} {content}

2. Static List page

This part of the work is actually very simple, just see if you can think up, like modify, delete we may follow the original practice, how to do it, just to update the static list page on a regular basis, update the frequency according to their own needs can be.

Here is my approach:

if (updatecache== $opper) {$rowInfo =; $listInfo =; $news =new newsmanagerimpl (); $all = $news->getallnews (); for ($i = 0; $ I < count ($all); $i + +) {$row = $all [$i];//splicing list information $listinfo.=; $listInfo. ={$row [' id ']}; $listInfo. ={$row [' title ']}; $listInfo. = view;//$ listinfo.= Delete;//$listInfo. = Modify; $listInfo. =;} List page static $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 way to re-read the data, and finally give you a few provinces to say I'm writing in this blind

Background words generally do not consider static, because the background is to see for themselves, as long as the performance is not very poor static meaning.

http://www.bkjia.com/PHPjc/621642.html www.bkjia.com true http://www.bkjia.com/PHPjc/621642.html techarticle The previous cache and now the page static is to speed up the site, if it is a small number of visits may not be a small site, but if the size of the site or a large number of visits, then the page ...

  • 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.