为加速PHP程序而努力
动态网站的内容加速显示十分重要,本文通过对 PHP 几个函数的深入讨论,提出了 PHP 网页压缩和缓冲的解决方案 一、介绍几个控制 PHP 输出的函数 PHP4 采用了缓冲机制,在你决定发送以前,所有内容只是存在于缓冲中,而不是直接发送给浏览器,虽然你可以用 header 和 setcookie 函数来实现,但是这两个函数相比于功能强大的输出函数来说只是一点“雕虫小技”。让我们来看看这些函数的真本事: void ob_start(void); 本函数告诉 PHP 处理器把所有输出重定向到内部缓冲,调用这个函数后,就不会有输出到浏览器。 string ob_get_contents(void); 本函数把输出缓冲返回到一个字符串,你可以用来把堆积起来的输出一起发送到浏览器。当然要先关掉缓冲。 int ob_get_length(void); 本函数返回输出缓冲的长度。 void ob_end_clean(void); 本函数清除并关闭缓冲。在输出到浏览器之前你需要使用这个函数。 void ob_implicit_flush ([int flag]) 本函数用来控制隐式缓冲泻出,缺省为 off,如果打开时,对每个 print/echo 或者输出命令的结果都发送到浏览器。 二、采用输出控制来压缩 PHP 的输出 在开始之前,要保证你的 PHP4 编译时支持 Zlib。 首先,初始化输出缓冲: 然后产生所有的输出内容。 页面生成以后,采用: 还要检查浏览器是否支持压缩数据,我们采用在变量 $HTTP_ACCEPT_ENCODING 中检查 "gzip, deflate"的办法: 下面我们分析怎样产生 gzip 输出: 三、缓冲 PHP 的输出 在 PHP4 里能很容易的实现缓冲,我们来看例子: 四、结论 PHP 输出缓冲函数在操作脚本输出方面十分有用,把缓冲压缩后输出能减少 80% 的输出时间,这对于存取其他数据资源(例如数据库或者 XML)来说,也是一个很好的缓冲机制。

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

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.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

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