为加速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

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.

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

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

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