如何将gzip内容作为PHP响应发送

时间:2022-10-27 11:32:33

my ajax response is very large its actually 900kb. so I need to gzip to improve the performance.

我的ajax响应非常大,实际上是900kb。所以我需要gzip来提高性能。

can anyone please help me to get gziped content from my php.

任何人都可以帮助我从我的PHP获取gziped内容。

Thanks in advance.

提前致谢。

3 个解决方案

#1


20  

Before outputing anything on the page throw in this:

在输出页面上的任何内容之前抛出:

ob_start("ob_gzhandler");

Then after your content follow it up with:

然后在您的内容跟进之后:

ob_end_flush();

And your content will be gzipped

并且您的内容将被gzip压缩

#2


10  

Option 1:

configure zlib.output_compression in your php.ini

在php.ini中配置zlib.output_compression

Doc: http://www.php.net/manual/en/zlib.configuration.php#ini.zlib.output-compression

Option 2:

Use : ob_gzhandler

使用:ob_gzhandler

Doc: http://php.net/manual/en/function.ob-gzhandler.php

Note:

900Kb is too much for an ajax response.

对于ajax响应,900Kb太多了。

#3


3  

If you cannot update your php.ini config file before using ob_gzhandler() you could try this too:

如果在使用ob_gzhandler()之前无法更新php.ini配置文件,您也可以尝试这样做:

ini_set('zlib.output_compression', 1);

#1


20  

Before outputing anything on the page throw in this:

在输出页面上的任何内容之前抛出:

ob_start("ob_gzhandler");

Then after your content follow it up with:

然后在您的内容跟进之后:

ob_end_flush();

And your content will be gzipped

并且您的内容将被gzip压缩

#2


10  

Option 1:

configure zlib.output_compression in your php.ini

在php.ini中配置zlib.output_compression

Doc: http://www.php.net/manual/en/zlib.configuration.php#ini.zlib.output-compression

Option 2:

Use : ob_gzhandler

使用:ob_gzhandler

Doc: http://php.net/manual/en/function.ob-gzhandler.php

Note:

900Kb is too much for an ajax response.

对于ajax响应,900Kb太多了。

#3


3  

If you cannot update your php.ini config file before using ob_gzhandler() you could try this too:

如果在使用ob_gzhandler()之前无法更新php.ini配置文件,您也可以尝试这样做:

ini_set('zlib.output_compression', 1);