Static php pages, static php pages. Php static page, php page static how to optimize page response time: Dynamic page static optimization database use server load balancer use cache if some content on the page is not often changed to php page static, php static page
How to optimize the page response time:
- Static dynamic page
- Optimize database
- Use server load balancer
- Use cache
If some content on the page is not changed frequently, you can use static dynamic pages. The advantage is: reduce the computing time of server scripts and reduce the server response time.
1,Static form of dynamic URL(Pseudo-static)
Example: http://xxx.com/index.php? C = play & id = 1111 =>
Http://xxx.com/play/1111.html (not a pure static page)
2,Buffer
BufferIt is actually a buffer zone, a memory address space, mainly used to store data areas.
Write a buffer. php file, and save, not directly save the file content in the disk, but first write the content into the buffer, when a buffer is full, writes data in the buffer to the disk. this is the buffer of the operating system.
When executing a PHP program, if there is output content, it will first be placed in the output buffer, and the data will be transmitted to the client or browser through tcp.
To put data in the output buffer, first enable the output buffer, use the php. ini file output_buffering = On or ob_start (), and then use ob_get_contents () to obtain the output buffer content.
3,PHP implements pure static page
Static html files are stored on the server disk.
Basic method:
- File_put_contents ()Function;
Int file_put_contents (string$filename
, Mixed$data
[, Int$flags
= 0 [, resource$context
])
If the operation succeeds, the number of bytes written to the file is returned. if the operation fails, false is returned.
- Use PHP built-in Cache mechanism to achieve static page-output_buffering
Ob function
Ob_start (); open the output buffer
Ob_get_contents (void); return the output buffer content
Ob_clean (void); clears the output buffer
Ob_get_clean (void); obtain the content of the current buffer and delete the current output buffer.
Three methods for generating static pages:
- Cache time added on the page
// Index.html exists and is valid (5 minutes) if (file_exists('index.html ') & lt; 300) {require_once 'index.html';} else {ob_start (); // connect to the database to obtain data and fill in the template echo 'helllo world'; file_put_contents('index.html ', ob_get_contents ();}?>
Manually set in the background and automatically generate
- Linux crontab scheduled scan program
Crontab-e // edit a crontab file. the file content is as follows: */5 * Directory of the php execution program/xx. php
Http://www.cnblogs.com/peida/archive/2013/01/08/2850483.html
4. pseudo-static
PHP processing pseudo-static: Regular Expression Matching
// Http://xxx.cn/xx/test4.php/2/11.html//http://xxx.cn/xx/test4.php? Page = 2 & id = 1, actual access path if (preg_match ('/\/(\ d +) \/(\ d1_0000.html /', $ _ SERVER ['path _ info'], $ matches) {$ param ['Page'] = $ matches [1]; $ param ['id'] = $ matches [2];}
Configure rewrite in Apache:
Http://myapps.com/detail/12.html ==> http://myapps.com/apps/detail.php? Id = 12 (actual access path)
Httpd. conf file: enable LoadModule rewrite_module modules/mod_rewrite.so
Extra/httpd-vhosts.conf files are configured as follows:
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "D:/wamp/www/myProject"
ServerName MyDomain.com
ErrorLog "log/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
RewriteEngine on
If the detaildirectory contains a 12.html file, access the file in the directory is given priority.
RewriteCond % {DOCUMENT_ROOT} % {REQUEST_FILENAME }! -D
RewriteCond % {DOCUMENT_ROOT} % {REQUEST_FILENAME }! -F
RewriteRule ^/detail/([0-9] * developer.html $/apps/detail. php? Id = $1
Http://www.onexin.net/apache-rewrite-detailed/
How to optimize page response time: Dynamic page static optimization database using server load balancer using cache if some content on the page is not frequently modified...