Share several common page static methods, and share some pages static _php tutorial

Source: Internet
Author: User
Tags php template

Share several common pages of static methods, share a few pages of static


What is PHP static

PHP static simple understanding is to make the site Generation page in the form of static HTML in front of the visitors, PHP static pure static and pseudo-static, the difference is that PHP generated static page processing mechanism is different.

Why make Web pages static

First, speed up the page to open the browsing speed, static pages do not need to connect the database open faster than the dynamic page has significantly improved;
Second, conducive to search engine optimization Seo,baidu, Google will first include static pages, not only is included in the fast also included in the whole;
Third, reduce the burden on the server, browse the Web without calling the system database;
Four, the website is more secure, HTML page will not be affected by PHP related vulnerability; Looking at a larger site is basically a static page, and can reduce attacks, anti-SQL injection.

When a database error occurs, it does not affect normal site access.
Generate HTML article Although the operation of the trouble, the program is complicated, but in order to better search, for faster, more secure, these sacrifices are worth.

How PHP generates static HTML pages

Generate static pages with PHP templates

PHP template Implementation of the static is very convenient, such as the installation and use of PHP smarty to achieve static site, you can also write a set of template parsing rules, common can imitate various types of CMS template rules.

1. Generate a static page using the PHP file read-write function and the OB cache mechanism
For example, the dynamic Details page address for a product is: http://xxx.com?goods.php?gid=112
So here we read the contents of this detail page from this address once, and then save as static page, the next time someone accesses this product Details page dynamic address, we can
Output the corresponding static content file that has been generated directly.

 
  Time ()) {//If not expired  echo file_get_contents ($goods _statis_file);//output static file contents exit;} else{//If expired unlink ($goods _statis_file);//delete the expired static page file Ob_start ();//Read data from the database and assign values to the relevant variable//include ("xxx.html");// Load the corresponding Product Details page template $content = Ob_get_contents ();//Assign the details page content to the $content variable file_put_contents ($goods _statis_file, $content);// Write content to the corresponding static file Ob_end_flush ();//Output Commodity Details page Information}}else{ob_start ();  Read the data from the database and assign the value to the relevant variable  //include ("xxx.html");//load the corresponding Product Details page template  $content = ob_get_contents ();//Assign the details page content to $ Content variable file_put_contents ($goods _statis_file, $content);//write to the corresponding static file Ob_end_flush ();//Output Commodity details page information}?>

2. Use NoSQL to read content from memory (in fact, this is not static but caching);

Take Memcache as an example:


 
  Connect (' Memcache_host ', 11211); $mem _goods_content = $mem->get ($goods _statis_content);   if ($mem _goods_content) {  echo $mem _goods_content;} else{Ob_start ();  Read the data from the database and assign the value to the relevant variable  //include ("xxx.html");//load the corresponding Product Details page template  $content = ob_get_contents ();//Assign the details page content to $ Content variables $mem->add ($goods _statis_content, $content, False, $expr); Ob_end_flush ();//Output Commodity details page information}?>

Memcached is the key value one by one corresponds, the key default maximum cannot exceed 128 bytes, the value default size is 1M, so 1M size satisfies most page size storage.
The above is the page static related methods, hoping to help friends

http://www.bkjia.com/PHPjc/939402.html www.bkjia.com true http://www.bkjia.com/PHPjc/939402.html techarticle share several common page static methods, share several pages static what is the simple understanding of static PHP static PHP is to make the site Generation page in the form of static HTML to show in the interview ...

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