Static page, static page _ PHP Tutorial

Source: Internet
Author: User
Tags website performance
Static pages and static pages. Static page, static page optimization technology for large websites: 1. SEO, optimization, 2. static page 3. memcache (memory cache) 4. overall goal of server cluster technology: improve static page, static page

Optimization technology for large websites:

1. SEO and optimization,

2. static page

3. memcache (memory cache)

4. server cluster technology





Overall goal: to improve the speed of website access, SEO objective: to improve the ranking of websites (to solve the problem of speed)

SEO: google optimization, Baidu optimization:



Today, we will talk about static pages:

First, let's talk about several concepts:

1. static website

Pure html document

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

However, do not assume that static websites with the suffix html are,



2. dynamic website (website)

Localhost/dir & file/var. php? Name = admin & id = 2

Different parameters are passed in the address bar to display different results.



3. pseudo-static website

Pseudo static:

The following url modes are used in the TP framework:

1,/pathinfo

2, MVC? M = & a =

3. rewrite mode: (different from pathinfo mode: fewer entry files are overwritten)

Modify apache configuration

Add an htacess file

Rewrite mode in tp framework, pseudo static:

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



Why do we need to change a dynamic website to a static one:

1,/* 1 = 1 */prevents SQL injection

2. dynamic websites are not conducive to SEO, because? The following parameters will change dynamically. when the search engine crawls, it does not know how to save them.

, Sina.com/index.html index. php? Act = index



Principle: do not operate the database whenever possible without obtaining data from the database



How to achieve static page:

Static page classification:

1. follow the form:

1. true or static

2. pseudo-static

2. according to the scope:

1. local static words (jquery, ajax)

2. all static



Search engine:

1. capture the content of your website, instead of capturing all the content in one brain.

2. you classify your content and rank your content based on your keywords.



How can we achieve SEO friendliness?

1. Baidu's suggestions:

Url length: no more than 255 bytes

Search engine crawling:

Triggered from the homepage: When a page captures its content and stores the content,
Www.sina.com/index.html

Www.sina.com/news/soprt.html

Because the shorter the capture, the more frequent it is, the faster the update, and the better you think.

In addition, each page has a limited crawling time, and each page can be allocated within 5 seconds at most.

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



2. the keywords desciption tag of the meta tag is also presented to the search engine.

SE will make a rough classification based on your keywords and descriptions.

You can disable search engines from capturing the content of our website:

In the web page codeAndTo add the nofollow attribute !! If it is a hyperlink, it is added to the label.

Rel = "nofollow!

(2)robots.txt



Keywords

Description



(3) Try not to use frame framset on the front end, which can be used in the background and frame * (because the background avoids search engine crawling)

(4) Use images instead of flash. jquery provides some special effects.

(5) add the alt attribute to each image as much as possible. when the image is not displayed, the alt prompt text is displayed first.



SEO optimization ----







How to achieve static page:

Implemented through php ob cache

Improve Ranking

Increase speed

With the emergence of 360 comprehensive search, Baidu ads are very cautious





1. implemented through php ob cache

You can test the website access speed by using tools.

Apache comes with the AB .exe tool.

It can detect the access speed of your website





Before php5.2, the ob cache is disabled by default. after php5.3, the ob cache is enabled by default.

In php. ini output buffering

Interview: development environment: apache2.2.6

Mysql version: 5.3





Static pages using php ob cache

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



(1) ob --- cache: first, buffer the output data to a space.

Then, the cached data of this space is displayed.

This is because some header information is provided by default. When an echo is encountered, data is sent to the browser.

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



Ob cache entry

No error prompt?

Introduce the principle of ob cache:

Php Cache:

(1) ob cache

First, determine whether to enable ob cache. if you enable ob cache, first put the output data in ob cache. if you do not enable ob cache

And then put it in the program cache.



(2) program cache

If ob cache is not enabled, the data is first cached to the program, and the echo is complete, and then the output is unified.



The browser also has cache:

The browser collects data and outputs the data only when it reaches a certain amount (ie more than 500 MB ).



How to obtain cached data



1. ob_start () first places the output data in the ob cache.

2. ob_clean () clears the cache, but it is not disabled.

3. ob_end_clean () clears the cache and closes the cache.

4. ob_flush () outputs the data cached by ob to the program cache.

5. ob_end_flush () outputs the ob cached data to the program cache and closes the ob cache.



Ob_flush (); // only outputs the data cached by ob to the program cache.

Ob_end_flush (); // disable the ob cache after the output



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

Browser cache: similar to the php program cache, each output is first output to the program cache, and then displayed to the browser after the output is complete.



PHP Cache mechanism:

1. ob cache. if ob cache is enabled, data is preferentially stored in ob cache.

2. program cache. if ob cache is not enabled, data will be cached to the program cache.



Case Study of static page:

News management system:

Output_buffering = Off Disable Cache





I made a supplementary remark:

Mysql data type:

Varchar (32): Number of digits displayed

Varchar (255 ):



How many bytes a letter or number occupies: UTF-8 2 Chinese characters: 3

Each gbk occupies 1 byte.



1 varchar indicates the length range of varchar (255) between 0 and)



Char fixed length string: the number of digits encoded by char (255). 255 indicates the number of digits displayed/saved.

Char () fixed length, no matter how much you store, all the specified bytes





Int: the maximum value is 429... 15175290987 billion bytes indicates 4 bytes

Tinyint: 1 byte 0-255 unsigned





Myisam: different from innodb:

1. myisam does not support transactions. innodb supports transactions.

2. myisam queries faster than innodb,

3. myisam does not support foreign keys. innodb supports foreign keys (the new mysql version already supports foreign keys)



Foreign key to maintain data integrity,

Transaction: a logical group of operations that constitute each unit of this group of operations, either successful or failed

Three features:

Atomic

Consistency



For a complete project, neither myisam nor innodb is uniform, but based on specific services



Problem: You need to query the database every time you access the database. frequent operations on the database increase the pressure on servers and databases, and the user may

The news content will not be updated within 10 minutes, so we do this:

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

When the second user visits this page, the static page is displayed.



There is a problem at this time:

What if the news is unfortunately updated?

1. judge





In the end, static pages should be generated when news is to be added or when news is modified.



Generate a static page when adding news:

After submission, the database is displayed and a static page is generated.



Template replacement content

Create a template file. when the style is basically fixed but the content is not sure, replace the data part with a placeholder.

Then, after obtaining the data, replace it

R fopen ()

W



Fgets () function to read a row of content (only)

Fopen () open document r w

Fwrite () writes content to the Open Document

Feof () test whether the current document has been read to the end

Close () after opening the document, remember to close it.

File_put_contents () writes content to a file

File_get_contents () reads the object content





1. Website category

2. website optimization Baidu's website optimization suggestions:

3. how to detect website performance (access speed)

4. start with ob cache

Optimization technology for large-sized websites in the region: 1. SEO: Optimized. 2. static pages. 3. memcache (memory cache). 4. overall goal of the server cluster technology: improve...

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.