


PHP realizes page staticization, pure staticization and pseudo-staticization
概念
PHP静态化分为:纯静态化 和 伪静态化;
纯静态化又分为:局部静态化 和 完全静态化
纯静态化:是把PHP生成的动态页面保存成静态的html文件,用户访问该静态页面,而不是用户每一次访问都重新生成一张相同的网页,优点就是减小服务器开销,
局部静态化:是生成的静态文件中,有局部的数据还是通过ajax技术动态获取的;
完全静态化:即不存在动态获取数据的情况,所以内容都来自静态的html页面
伪静态化:Apache服务器rewrite配置
纯静态化的实现
利用php内置的ob函数实现页面的静态化,大概步骤如下:
<?php ob_start();//开启缓存 ?> <p>我是要生成的静态内容,也可以在该处链接数据库生成动态内容于此</p> <?php file_put_contents( 'index.html', ob_get_clean() );//把生成的静态内容保存到index.html文件,而不是输出到浏览器 ?>
触发系统生成纯静态化页面
方法:页面添加缓存时间;手动触发
页面添加缓存时间
<?php $file_name = 'index.html'; if(file_exists( $file_name ) && filemtime( $file_name ) - time() < 10 ){//如果文件是存在并且最后修改时间小于设定时间 10s //filemtime( $file_name );//得到文件最后修改时间 //time();//当前时间 require_once( $file_name );//引入文件 }else{ ob_start( ); ?> <p>我是要生成的静态内容</p> <?php file_put_contents( $file_name, ob_get_contents() )//输出到浏览器 }
如果后台数据存在更细,定时刷新不能及时更改静态页面,怎么办?所有引入了手动触发的功能
Linux下的crontab定时扫描程序
*/5****php/data/static/index.php
PHP伪静态
Apache服务器rewrite配置
在httpd.conf文件中,找到
#注释:去掉前边的" # "开启rewrite服务,重启服务器生效
#LoadModule rewrite_module modules/mod_rewrite.so
#注释:http-vhosts.conf文件是虚拟域名配置的文件,开启改文件可以配置虚拟域名,一般默认是开启的
#Include conf/extra/httpd-vhosts.conf
rewrite伪静态配置
<VirtualHost *:80> 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 </VirtualHost>
也可用.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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
