search
Homephp教程php手册加速你的页面--数据压缩

加速你的页面--数据压缩

Jun 13, 2016 am 11:21 AM
noacceleratecompressionslowimplementdatatimeyesofKnowwebsitenetwork transmissionScriptslowpage

最近偶的网站越来越慢,不是脚本执行时间慢,是网络传输速度慢。
知道http1.1支持gzip编码的数据,所以试试将自己的页面压缩压缩...
(在php.ini可以设置,直接输出为gzip编码,不过没试过)

上网搜到一个gzdoc.php,改了改,让大家共同琢磨琢磨。
ob_start();//打开输出缓冲
ob_implicit_flush(0);//

//*****************************************************************//
//函数名:canGzip()
//作用:检查客户浏览器是否支持gzip,x-gzip编码
//参数:
//返回值:支持的编码类型"gzip", "x-gzip", 返回false代表不支持
//*****************************************************************//
function canGzip()
{
//if (headers_sent() || connection_status)
//return false;

if (strpos('King'.$_SERVER["HTTP_ACCEPT_ENCODING"], 'gzip') !== false)
return "gzip";

if (strpos('King'.$_SERVER["HTTP_ACCEPT_ENCODING"], 'x-gzip') !== false)
return "x-gzip";

return false;
}

//*****************************************************************//
//函数名:doGzipOut($level, $debug)
//作用:对输出缓冲的数据进行压缩并输出
//参数:$level代表压缩级别, 0 = 不压缩, 9 = 最大压缩率
// $debug代表是否输出调试信息, 1 = 输出, 0 = 不输出
//返回值:
//*****************************************************************//
function doGzipOut($level = 1, $debug = 0)
{
$ENCODING = canGzip();
if ($ENCODING)
{
echo "nn";
$contents = ob_get_contents();


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists

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.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version