Home  >  Article  >  Backend Development  >  Page staticization, page static_PHP tutorial

Page staticization, page static_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:59:10919browse

Page staticization, page static

Optimization technology for large websites:

1, SEO, one kind of optimization,

2, page Static

3, memcache (memory cache)

4, server cluster technology





Overall goal: improve the website Access speed, SEO purpose: improve website ranking, (the solution is speed)

SEO: Google’s optimization, Baidu’s optimization:



Today, start with the page In terms of staticization:

Let’s talk about a few concepts first:

1. Static URL

Pure html document

http://localhost/dir&file /var.html

But don’t think that the suffix is ​​html is a static website,



2, dynamic URL (website)

localhost/dir&file /var.php?name=admin&id=2

Display different results according to the different parameters passed by the user in the address bar



3, pseudo-static URL

Pseudo-static:

In TP framework, several url modes:

1, / pathinfo

2, MVC ?m=&a=

3, rewrite mode: (difference from pathinfo mode: rewriting without entry file)

Modify apache configuration

Add htacess file

tp framework Medium rewrite mode, pseudo-static:

localhost/dir&file/news-id/2/name/admin.html



Why change the dynamic website to static Format:

1, /*1=1*/ Prevent sql injection

2. Dynamic websites are not conducive to SEO, because? The following parameters will change dynamically. When crawled by search engines, I don’t know how to save

, sina.com/index.html index.php?act=index



Principle: Try not to operate the database without obtaining data from the database



How to achieve page staticization:

Classification of page staticization:

1, according to the form:

1, true static

2, pseudo-static

2, according to the range:

1, partial static Words (jquery, ajax)

2. All static



Search engine:

1. Crawl the content of your website, not all at once How about crawling all the content and putting it into one piece

2, but classifying your content and ranking it according to your keywords



How about being SEO friendly?

1. Baidu’s suggestion:

URL length: no more than 255 bytes

When crawled by search engines:

From the homepage Start triggering: when encountering a page, grab its content and save the content,
www.sina.com/index.html

www.sina.com/news/soprt.html

Because the shorter the page is, the earlier it is crawled, the more frequently it is crawled, and the faster it is updated. I think you are good

And the crawling time for each page is limited, and each page is allocated a maximum of 5 seconds.

Of course, the better the website, the higher the ranking, the longer the time allocated



2. The keywords desciption tag of the meta tag is also made for search engines to see

However, SE will roughly classify it based on your keywords and descriptions

You can prevent search engines from crawling the content of our website:

In the web page code and < /head>, add the nofollow attribute! ! If it is a hyperlink, just add

rel="nofollow" to the tag!

(2) robots.txt



Keywords

description



(3) Try not to Use frame frameset in the foreground, you can use it in the background, frame* (because the background avoids search engine crawling)

(4) flash, try to use pictures instead, jquery to do some special effects

(5) For pictures, try to add alt attributes to each picture. When the picture is not displayed, the alt prompt text is displayed first



SEO optimization----







How to achieve page staticization:

Achieved through php's ob cache

Improve ranking

Improve speed

With the emergence of 360 comprehensive search, Baidu advertising is very cautious





1, achieved through php's ob cache

You can test the access speed of the website through tools

apache comes with ab.exe. This tool

can detect the access speed of your website





Before php5.2, the ob cache was turned off by default. After php5.3, the ob cache was enabled by default

In php.ini output buffering

interview : Use development environment: apache2.2.6

mysql version: 5.3





Use php's ob cache to achieve page staticization

1. Cache: smarty cache, ThinkPHP framework cache, PHP ob cache



(1) ob---cache, first buffer the output data into a space

Then display the cached data of this space when displaying

Because there is some header information by default, and then when it encounters echo, the data will be sent to the browser

Because the default header It has been sent to the browser with the echo



Introduction to ob cache

Is there no error message?

The principle of introducing ob cache:

PHP cache:

(1) ob cache

First judge whether to enable ob cache. If you If it is enabled, first put the output data into the ob cache. If you do not enable the ob cache

, then put it into the program cache



(2) Program cache

That is, if the ob cache is not turned on, cache the data into the program first, and then output it uniformly after the echo is completed



Browsers also have cache:

The browser first saves the data and waits until it reaches a certain amount (ie more than 500 MB) before outputting it



How to obtain cached data



1, ob_start() First put the output data into the ob cache first

2, ob_clean() Clear the cache, but not close it

3, ob_end_clean() Clear the cache and also close the cache

4, ob_flush() Output the ob cached data to the program cache

5, ob_end_flush() Output the ob cached data to the program cache and close it ob cache



ob_flush(); //Just output the ob cache data to the program cache

ob_end_flush(); //Cache the ob cache after output Close



flush() will output the data cached by the program to the browser cache

Browser cache: similar to PHP program cache, first output each Output to the program cache, and then display to the browser after the output is completed



PHP’s caching mechanism:

1, ob cache, if ob cache is turned on, the data will be given priority Put it in the ob cache

2. Program cache. If the ob cache is not turned on, cache the data in the program cache



Page staticization case:

News management system:

output_buffering = Off Turn off caching





Talking about the supplementary lesson:

mysql data type:

varchar(32) : How many digits are displayed?

varchar(255) :



How many bytes does a letter or number occupy: utf- 8 2 Chinese characters: 3

gbk All occupy 1 byte



1 varchar The length range represented is between 0-65535 varchar(255)



char fixed-length string: char(255) The number of encoding digits, 255 refers to how many digits are displayed/saved

char() fixed-length, no matter what you store How many, the number of bytes specified by the station





int: The longest is 429. . 15175290987 Ten billion represents 4 bytes

tinyint: 1 byte 0-255 unsigned





myisam: and innodb: difference

1, myisam does not support transactions, innodb supports transactions

2, myisam query speed is faster than innodb,

3, myisam does not support foreign keys, innodb supports foreign keys (mysql The new version already supports foreign keys)



Foreign keys maintain data integrity,

Transactions: a logical set of operations, each unit that makes up this set of operations , either all succeed or all fail

Three major features:

Atomic

Consistency



Complete project, Not all myisam is unified, nor are all innodb, but based on specific business



Problem: The database must be queried every time it is accessed, and the database is frequently operated, causing increased pressure on the server and database. , and the user may not update the news content within

10 minutes, so we do this:

After the first person visits, a static page is generated,

The second Personal, 3, 4 When I visit this page again, the static page is directly displayed



There is a question at this time:

What should I do if the news is unfortunately updated?

1. Judgment





Finally, when you want to add news or modify news, you should generate a static page



Generate a static page when adding news:

After submission, it will be displayed and stored in the database, and then a static page will be generated



Involves template replacement content

Create a template file. When the style is basically fixed but the content is uncertain, first replace the data part with a placeholder

Then, after obtaining the data, replace it

r fopen()

w



fgets() function, read a line of content (just)

fopen() open the document r w

fwrite() writes content to the opened document

feof() tests whether the current document has been read to the end

fclose() be sure to close the document after opening it

file_put_contents() Write content to a file

file_get_contents() Read the content of a file





1, website category

2. Website optimization Baidu’s suggestions for website optimization: 5 points

3. How to detect website performance (access speed)

4. The beginning of ob cache

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1099825.htmlTechArticlePage staticization, page static optimization technology for large websites: 1. SEO, one kind of optimization, 2. Page static 3. memcache (memory cache) 4. The overall goal of server cluster technology: improve...