简体   繁体   English

用gzhandler php压缩gzip的4kb文件

[英]gzip compression with gzhandler php for 4kb file

I wanted to implement a gzip compression functionality for json output that my php script does, for a quicker way I decided to gzip the json content via this function ob_start("ob_gzhandler"); 我想为我的php脚本实现json输出的gzip压缩功能,为了更快捷的方式,我决定通过此函数ob_start("ob_gzhandler");对json内容进行gzip压缩ob_start("ob_gzhandler");

The Original file json content output is around 4kb uncompressed, and it becomes 0.7kb after compression. 原始文件json内容输出未压缩约4kb,压缩后变为0.7kb。

Does it make any sense to compress at such small file size or I should not compress at all, as it won't make any significant difference on the speed of download and it might be a bad idea to put more strain on my vps cpu. 在这么小的文件大小下进行压缩是否有意义,或者我根本不应该进行压缩,因为这不会对下载速度产生任何重大影响,并且对我的vps cpu施加更大的压力可能不是一个好主意。

If you are running Apache and have mod_deflate you can add the following to your .htaccess . 如果您正在运行Apache并且具有mod_deflate ,则可以将以下内容添加到.htaccess

AddOutputFilterByType DEFLATE text/json application/json 

For NGINX you can add the following to your site.conf file. 对于NGINX,您可以将以下内容添加到site.conf文件中。

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_types text/json application/json;

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

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