PHP is an ultra-Simple Method for static pages. php implements static pages.
Why static pages?
1. Dynamic File Execution Process: syntax analysis-compile-run
2. static files do not need to be compiled. This reduces the running time of server scripts, reduces the server's response time, runs directly, and responds quickly. If some content on the page is not changed frequently, static dynamic pages are very effective acceleration methods. (Purely static, pseudo static, or PHP interpreter required)
3. Generating static URLs is good for SEO, crawlers can capture and record, and rankings can be improved.
How to optimize the page Response Time
1. static dynamic pages
2. Optimize the database
3. Server Load balancer
4. Use cache, etc.
// Static dynamic pages are generally used for areas that are not frequently changed. Static pages are not applicable for areas that are frequently changed, and pseudo static pages (such as Weibo) are available)
Static details
1. Pure static data is divided into local static data (local dynamic data, dynamic data acquisition using AJAX) and pure static data.
Pseudo-static: Change the URL (server support is required, such as apache)
2. From the URL structure and Page name, the pseudo-static and static pages are the same. The pseudo-static page suffix can be html htm or directory format
Pseudo-static only changes the URL format, but it is still a dynamic page.
Static pages can save server resources, while pseudo-static pages strictly increase server resource consumption.
In summary, in SEO, the functions of pseudo-static pages are the same as those of static pages, but pseudo-static pages are essentially dynamic pages, so resource consumption is the same as that of dynamic pages, in addition, the Rewrite server consumes additional resources.
Buffer Cognition
1. Enable buffer
• Enable output_buffering in php. ini
• Use the ob_start () function in the PHP file to enable
; Default Value: Off; Development Value: 4096; Production Value: 4096; http://php.net/output-bufferingoutput_buffering = 4096
2. Obtain the buffer content
Output_buffering = on must be enabled before the ob_get_contents () function can be called. However, if output_buffering is not enabled, ob_get_contents () can also be used when the ob_start () function is called in the header file.
Ob_get_content (); // return the content of the output buffer;
How PHP achieves pure Static Page
Basic Method
1. file_put_contents
2. Use the PHP built-in cache mechanism to achieve Static Page output_buffering
Ob_start () // If php. if ini is enabled, a new output buffer is enabled here; ob_get_contents () // gets the output buffer content; ob_clean () // clears the output buffer content, but the output buffer ob_get_clean will not be deleted. // get the output buffer content and delete the output buffer, which is equivalent to ob_get_contents and ob_end_clean)
The code below will not be output during running.
The reason is that the output buffer is cleared.
ob_start();echo 777;echo 000;ob_clean();echo ob_get_contents();
Pure static implementation, code and implementation logic reference:
<? Php/*** trigger the system to generate a purely static page business logic * There are three solutions: * 1: timed scanning program (which is handled using crontab) * 2: manual triggering method, manually triggered * Third: cache time added to the page, on the page, control the time to operate * // ====================================== ====================/// create a pure static file step // 1. Connect to the database, then retrieve data from the database // 2. Fill the obtained data in the template file // 3. Convert the dynamic page into a static page, generate a static file. ============/// follow these steps to achieve page static in PHP: // 1:. php requests database data: mysql, mysqli, or PDO extension // 2: Output. database data requested by php: Generally, the data in the array form retrieved from the database is assigned to a new array, and the output // 3: Include the.html file in a.php: directly through require_once () function or inclde_once () // 4: Enable data cache ob_start () => alipay', ob_get_clean (); // header ("content-type: text/htm; charset = UTF-8 "); if (is_file ('. /index.html ') & (time ()-filemtime ('. /index.html ') <1200) {// load the static file require_once ('. /index.html ');} else {// If the cache is invalid, generate a new // import database link operation require_once ('. /db. php '); $ SQL = "select * from news where 'category _ id' = 1 and 'status' = 1 limit 4"; try {$ db = Db :: getInstance ()-> connect (); $ result = mysql_query ($ SQL, $ db); $ newsList = array (); while ($ row = mysql_fetch_assoc ($ result )) {$ newsList [] = $ row;} catch (Exception $ e) {// TODO} ob_start (); require_once ('template/index. php '); // introduce the template file file_put_contents ('. /index.html ', ob_get_contents (); // generate a static file // ob_clean ();}
Local dynamic implementation in static pages
Use the ajax request file in Jquery to obtain the returned JSON data, and then apply it to the template.
Pseudo-static
The Nginx server does not support the path info mode by default and requires additional configuration.
Apache pseudo-static settings
1. Enable apache mod_rewrite.so and configure it in httpd. conf.
You can use phpinfo to check whether loaded modules has this module.
2. inculde conf/extra/httpd-vhosts.conf virtual hosts support, virtual domain name Configuration
3. Edit the vartual host file
4. Add the host file of the local machine to the configured domain name (if you need to test the Local Machine for windows)
5. pseudo-static Configuration
-5.1 rewrite engine on
-5.2 write rules
^/post/([0-9]*).html$ /post.php?id=$1
In the virtualhost segment
Post. php
<?php echo 'this is '.$_GET['id'];
Then you can access a.com/123.html and return this is 123.
Extension: If the directory contains a real file named 123.html, dynamic post 123 is still loaded.
So how to set it? If you want the current file to have a real static file, you need to configure the following:
RewriteEngine onRewriteRule ^/post/([0-9] * developer.html $/post. php? Id = $1 # The Directory RewriteCond % {DOCUMENT_ROOT} % {REQUEST_FILENAME} exists }! -D # The file RewriteCond % {DOCUMENT_ROOT} % {REQUEST_FILENAME} exists }}! -F
The above two statements mean that if there is a requested directory or file under the root directory, use
Of course, this should be placed on the rewrite.
Nginx pseudo-static
The pseudo-static mode affects the server performance. The more the server is, the better the server is.
The ultra-Simple Method for Static Page implementation in PHP is to share all the content with you in the editor. I hope to give you a reference and support for the help house.