简体   繁体   English

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

[英]How to get send gzip content as PHP response

my ajax response is very large its actually 900kb. 我的ajax响应非常大,实际上是900kb。 so I need to gzip to improve the performance. 所以我需要gzip来提高性能。

can anyone please help me to get gziped content from my php. 任何人都可以帮助我从我的PHP获取gziped内容。

Thanks in advance. 提前致谢。

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压缩

Option 1: 选项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 Doc: http//www.php.net/manual/en/zlib.configuration.php#ini.zlib.output-compression

Option 2: 选项2:

Use : ob_gzhandler 使用: ob_gzhandler

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

Note: 注意:

900Kb is too much for an ajax response. 对于ajax响应, 900Kb太多了。

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

ini_set('zlib.output_compression', 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM