【发布时间】:2013-05-21 17:15:47
【问题描述】:
我通过这样做在我的 php 脚本上启用了 gzip:
<? ob_start("ob_gzhandler");
?>
<?php
header('Content-Type: application/json');
header('Accept-Encoding: gzip');
/* Request data, transform it, json_encode it, echo */
?>
<? ob_flush(); ?>
这已经在几个主机上工作了,但是当我搬到 Hosting24 时,它根本无法工作。
我还在 cPanel 的优化网站部分启用了“压缩所有内容”,同时将 .htaccess 文件编辑为如下内容:https://stackoverflow.com/a/8262235/2237587
Hosting24 向我保证:
Our servers support mod_gzip, mod_deflate by default.
To use GZIP, please call the function ob_start("ob_gzhandler"); at the top of your script. Also remember to call the function ob_flush(); at end
我正在这样做,但它不适用于 Hosting24。当我在另一个服务上使用相同的脚本(在 000webhost 和 Arvixe 上测试)时,响应被压缩了。
接下来我可以尝试什么来压缩它,老实说,我不知道为什么它已经不起作用了。
【问题讨论】:
-
感谢您的建议,但没有成功
-
GZIP 在我将内容类型设置为 text/html 时有效,但我需要将内容类型设置为 application/json 才能与 AFNetworking 很好地配合使用。这是 Hosting24 不接受 application/json 作为内容类型的问题吗?
标签: php .htaccess gzip zlib mod-deflate