Home > Backend Development > PHP Tutorial > PHP page staticization is really static_PHP tutorial

PHP page staticization is really static_PHP tutorial

WBOY
Release: 2016-07-13 17:18:40
Original
1032 people have browsed it

The previous caching and the current page staticization are all used to speed up the website. If it is a small website with few visits, it may not be needed. But if the website size or the number of visits is large, then page staticization and caching will be Reflecting their respective values, let’s first understand the classification of static pages

Categories of static pages:

1, according to the form:

1) True static

2) Pseudo-static

2, according to range:

1) Local static words (jquery, ajax)

2) All static

Staticizing the page can speed up the website and also perform SEO optimization, because search engines tend to crawl static pages, and the SEO standards for different search engines may be different. A link to Baidu search engine optimization is provided below

This time I will share with you the page true static technology. This time I will use a simple news management system as an example to introduce the use of true static technology. The project uses the MVC architecture to implement it.

1. True static understanding

True static means changing the jsp, php, and aspx we visited previously into html, retaining the previous page effects and business logic, reducing the pressure on the server, and allowing the website to be well included. But true static also has a disadvantage, that is, too many static pages take up server space, and maintenance is not very convenient.

2 Start static news management system

1. View the detailed information of a single piece of data as quickly as possible through the list page (such as viewing the detailed content of a certain news through the news list)

If there is no static premise, our approach may be to click on the title of the list page to pass an ID, and then query a single piece of data and display it on a page, so that every time we click on the link, we will access the database. , so the pressure on the server will inevitably increase. It is advisable to generate a corresponding detailed page every time you add data

(1) Simple backend management page

(2) Operation of adding news

if(add==$opper){
    $news=new NewsManagerImpl();
    $title=$_POST[title];
    $content=$_POST[content];
    $result=$news->addNews($title, $content);
    if($result>0){
    	//生成静态html(用于查询单条数据)
    	$fp=fopen(../static/news-id-.$result..html, w);
    	$ftpl=fopen(../tpl/newsDetail.tpl, r);
    	
    	while(!feof($ftpl)){
    		$row=fgets($ftpl);
    		//替换相应的位置
    		$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();
}
Copy after login

Let’s take a look at the template file newsDetail.tpl.

Copy after login


新闻标题 新闻内容
{title} {content}

2. Static list page

This part of the work is actually very simple. It depends on whether you can think about it. For example, we can follow the original method of modifying and deleting. We can do it however we want. We only need to regularly update the static list page. Yes, you can update as often as you need.

Here’s how I do it:

if(updatecache==$opper){
	$rowInfo=;
	$listInfo=;
	$news=new NewsManagerImpl();
	
	$all=$news->getAllNews();
	for ($i = 0; $i < count($all); $i++) {
		$row=$all[$i];
		//拼接列表信息
		$listInfo.=;
		$listInfo.={$row[&#39;id&#39;]};
		$listInfo.={$row[&#39;title&#39;]};
		$listInfo.=查看;
		//$listInfo.=删除;
		//$listInfo.=修改;
		$listInfo.= ;
	}
	//列表页静态化
	$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);
}
Copy after login

Is it just a simple operation of re-reading the data? Finally, I will give you some renderings to save you the trouble of saying that I am writing nonsense here.

PHP page staticization is really static_PHP tutorial

PHP page staticization is really static_PHP tutorial

Generally speaking, there is no need to consider staticization in the background, because the background is for yourself to see. As long as the performance is not very poor, staticization does not make much sense.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621642.htmlTechArticleThe previous caching and the current page staticization both speed up the website. If the number of visits is small Small sites may not need it but if the site size or traffic is huge then the page...
Related labels:
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