这是本人根据自己学习PHP技术页面静态化的过程所写的学习笔记,希望能够对大家有所帮助。 1、真静态化的方案 (1)使用PHP自身的缓存机制 a.配置PHP配置文件php.ini display_errors= On output_buffering= Off error_reporting= E_ALL | E_STRICT 2、常用函
这是本人根据自己学习PHP技术页面静态化的过程所写的学习笔记,希望能够对大家有所帮助。
1、真静态化的方案
(1)使用PHP自身的缓存机制
a.配置PHP配置文件php.ini
display_errors= On
output_buffering= Off
error_reporting= E_ALL | E_STRICT
2、常用函数
(1)ob_get_contents()可以获取output_buffering的内容
(2)ob_clean()可以清空output_buffering的内容
(3)ob_end_clean()可以关闭output_buffering同时清空output_buffering的内容
(4)ob_end_flush()可以把ob缓存的内容输出并关闭ob
(5)ob_flush()可以把ob缓存的内容输出,但是不关闭ob
(6)flush()可以输出程序缓存的内容
(7)str_repeat("0",1024)可以重复输出1024个0test2.php(以上函数的实际应用)
<?php //开启缓存【通过php.ini也可以开启缓存】 ob_start(); echo "yyy"; header("content-type:text/html;charset=utf-8"); echo "hello"; //ob_clean()可以清空output_buffering的内容 //ob_clean(); //ob_end_clean()可以关闭output_buffering同时清空output_buffering的内容 // ob_end_clean(); //ob_end_flush()可以把ob缓存的内容输出并关闭ob // ob_end_flush(); //ob_flush()可以把ob缓存的内容输出,但是不关闭ob // ob_flush(); echo str_repeat("0", 1024); echo "yyy"; // header("content-type:text/html;charset=utf-8"); //ob_get_contents()可以获取output_buffering的内容 // $content = ob_get_contents(); // file_put_contents("d:/log.txt", $content); ?>
3、静态化页面适用于大型网站
(1)访问量巨大
(2)多次查询结果相同的网站(比如新闻网站)
(3)实时性要求不高的网站
4、页面静态化传统解决方案的基本思路
(1)第一次访问页面时,从数据库查询出所需数据,组成网页
(2)使用ob的缓存机制,把内容缓存到html页面
(3)以后访问此页面时,直接访问html页面

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
