php page static technology

The template engine of many frameworks has the function of static page in order to optimize the running time of the website

Static is divided into two kinds of pure static and pseudo static

1. Purely static

The purely static display is the actual static page.
Run the PHP program to determine whether there is a static page. If there is a static page, if there is a static page, generate a static page and then display it. The
implementation method is PHP's ob buffer

    //PHP程序一系列逻辑 并将要展示的数据赋值给某些变量准备在模板中使用
    ob_start();//开启ob缓冲区 也可以在配置文件中开启 
    require_once('template/index.php');//引入模板文件 也有可能是html文件 此时模板中的变量已全部解析替换
    $s = ob_get_contents(); //将缓冲区的内容取出
    file_put_contents('./index.html', $s);//将缓冲区的内容写入一个静态文件 一般的做法是将文件路径加密之后作为文件名

2. Pseudo-static

Pseudo-static means that it looks static on the url. In fact, it is still a dynamic process.
http://www.baidu.com/home/1.html
There are two implementation methods:
1. Project routing analysis takes out the suffix
  $_SERVER In the variable, you can grab all the nodes on the url and split them into what you want to replace the combination of the combination
2. Is the Apache rewrite function rewrite
  turns on the Apache rewrite function to create the .htaccess file write in the project directory Rules, for
example, write the following

RewriteEngine on  
RewriteRule ^localhost/([a-zA-Z]{1,})/([0-9]{1,})\.html$ localhost/$1.php?id=$2

For example, if the browser visits localhost/home/1.html, it is actually rewritten by apache to localhost/home.php?id=1
. There are a lot of detailed rules for the rewriting rules, and friends who are interested can study it.

The static technology means that these two kinds of pseudo-static are just that the URL looks good, but it does not optimize the program.

Guess you like

Origin blog.csdn.net/weixin_43452467/article/details/110368290