2013-05-21 102 views
0

我已經這樣做Gzip已在我的PHP腳本:啓用GZIP壓縮PHP腳本

<? 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上測試)時,響應被壓縮。

我可以嘗試下一步來獲得它壓縮,說實話,我不知道爲什麼它不工作已經。

+0

感謝您的建議,但它沒有工作 – Simon

+0

當我設置內容類型爲text/html時,GZIP工作,但我需要內容類型爲application/json,與AFNetworking很好地協同工作。 Hosting24不接受application/json作爲內容類型是否存在問題? – Simon

回答

0

更換此:

header('Content-Type: application/json'); 

header('Content-Type: text/javascript'); 

解決了這一問題。不確定這是否是Hosting24的問題。 text/javascript允許我使用AFNetworking的json請求,所以我很滿意結果。