The benefits of generating static pages

 

 

 

Optimize the response time of the page

   The reason: When accessing a site, page load speed is very slow, the user experience is not good, churn

solution:

1, dynamic static pages

2, optimizing the database

3, using load balancing

4,  using the cache  redis and memcache

  

Dynamic static pages

 If the page does not change often, and user access to large, dynamic static pages is a very effective solution. 5 min or 10 min

 

Essence: to generate static html file

Benefits: reduce the running time server script     

      Reducing the response time of the server

 

 

PHP execution order file

   Parsing ->   compile ->  run

Html page only need to run

 

First, the criteria of large sites

1, pv value (page views) website traffic:

The concept: a website, all pages within 24 hours a day, the total amount being accessed, reach thousands of levels, or a few million more.

2, uv value (unique visitor) unique visitors:

The concept: a website, within 24 hours a day, how many users visit our website. uv value of hundreds of thousands,

3, independent ip,

The concept: a website, within 24 hours a day, the number of independent ip to access our site.

If you want to consider the company's local area network, uv slightly larger than the value of independent ip.

Second, the large sites which bring problems:

1, high concurrency.

Concurrency: a site in (within 1 second) the same point in time, how many users are requesting the same website address.

2 large traffic (bandwidth)

Bandwidth demand increases.

3, data storage problems.

When the data table inside the record is very large, it is the capacity to achieve the GT class, to quickly find the desired data.

 

Third, high concurrency how to solve:

Site architecture, using layered design, the use of load balancing and clustering.

 

Fourth, how to solve the large flow

1 , the resources to prevent the site from hotlinking present in some large resource type of website

 

2 , reducing the http request,

You can put some style css files and js, some of the background, combined into one file.

 

3 , configure the browser cache

Some not very frequent update of resources, such as css, js, images, cached in the browser when the browser requests the same resource, taken directly from the browser cache inside.

 

 

 

4 , the compressed configuration, reduce the amount of data transmission

5 , can compare traffic accounts for some of the resources to deploy a separate server.

6 , spend money on bandwidth.

 

Five large storage solutions:

The ultimate goal: not less query the database query the database when querying the database, to quickly query to the data.

1 , using the cache server.

(1) disk cache (static pages Technology)

 

(2) memory cache

 

Memory caching:

memcache, redis, mongodb, mysql of memory storage engine

2, optimized database

Sixth, static pages Technology

To a dynamic (operation database) php page, it is converted into a static page .html

Implementation steps;

A http request, the data returned in two parts, and the response information in response to the head body.

(1) get the content data in response to the body. (Ob buffer)

(2) in response to the content body data, is written to the html file, (file_put_contents)

(3) direct access to the html file.

1 , ob cache content:

ob Cache: output_buffering (output buffer) for buffering the data in response to the content body.

How to open:

The first way: in the php.ini file,

 

The second way: use ob_start () function in the page, to open.

The difference is that in two ways, ob_start () is only valid in the current page,

 

2, commonly used functions

ob_start (); Open

ob_get_contetns (); Get data contents of the cache and ob.

ob_clean () ; // clear the cache and data ob, ob cache does not close.

ob_end_clean (); // clear the cache and data ob, ob and close the cache.

ob_flush (); // data inside the ob to the refresh buffer (movement, push) to the program cache, the cache is not closed ob.

ob_end_flush (); // data inside the ob to the refresh buffer (movement, push) to cache the program and close ob cache.

3 , static website:

True Static: real generate a html page.

Pseudo-static: a static page is accessible from the surface, in fact or dynamic page is accessed. For example, the following address:

http://www.abc.com/news-music-id12_10.html

Actually visit: http://www.abc.com/news.php?type=music&id=12 & Page = 10 pages.

Pseudo-static mainly in favor of seo.

Method to realize:

True static ways:

The first: the use of ob caching techniques.

The second: use a template replacement technology

Pseudo-static implementation: use the apache rewrite mechanism (url rewriting mechanism)

 

Which site is suitable for real static?

Web pages visited more frequently, not very frequent updates, such as some types of news sites, some sites are not suited for real-time updates, such as stock type of site,

 

Guess you like

Origin www.cnblogs.com/huake69/p/11550966.html