PHP realizes page staticization, pure staticization and pseudo-staticization

藏色散人
Release: 2023-04-08 12:06:02
forward
3917 people have browsed it

PHP realizes page staticization, pure staticization and pseudo-staticization

概念

PHP静态化分为:纯静态化 和 伪静态化;

纯静态化又分为:局部静态化 和 完全静态化

纯静态化:是把PHP生成的动态页面保存成静态的html文件,用户访问该静态页面,而不是用户每一次访问都重新生成一张相同的网页,优点就是减小服务器开销,

局部静态化:是生成的静态文件中,有局部的数据还是通过ajax技术动态获取的;

完全静态化:即不存在动态获取数据的情况,所以内容都来自静态的html页面

伪静态化:Apache服务器rewrite配置

纯静态化的实现

利用php内置的ob函数实现页面的静态化,大概步骤如下:

 

我是要生成的静态内容,也可以在该处链接数据库生成动态内容于此

Copy after login

触发系统生成纯静态化页面

方法:页面添加缓存时间;手动触发

页面添加缓存时间

 

我是要生成的静态内容

Copy after login

如果后台数据存在更细,定时刷新不能及时更改静态页面,怎么办?所有引入了手动触发的功能

Linux下的crontab定时扫描程序

*/5****php/data/static/index.php
Copy after login

PHP伪静态

Apache服务器rewrite配置

在httpd.conf文件中,找到

#注释:去掉前边的" # "开启rewrite服务,重启服务器生效
#LoadModule rewrite_module modules/mod_rewrite.so
#注释:http-vhosts.conf文件是虚拟域名配置的文件,开启改文件可以配置虚拟域名,一般默认是开启的
#Include conf/extra/httpd-vhosts.conf

rewrite伪静态配置

 ServerAdmin webmaster@dummy-host.example.com DocumentRoot "c:/Apache24/docs/dummy-host.example.com" ServerName dummy-host.example.com ServerAlias www.dummy-host.example.com ErrorLog "logs/dummy-host.example.com-error.log" CustomLog "logs/dummy-host.example.com-access.log" common #配置规则如下所示 RewriteEngine on RewriteRule ^/vidio/([0-9]*).html$ /vidio.php?id=$1 
Copy after login

也可用.htacess文件,放在网站目录下,无需重启服务器。

更多php相关知识,请访问php教程

The above is the detailed content of PHP realizes page staticization, pure staticization and pseudo-staticization. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!