繁体   English   中英

Gzip数据将通过php发送到浏览器

[英]Gzip data to be sent to browser in php

我想将Gzip数据(css,js)发送到php中的浏览器。 我尝试了gzcompressgzencode,但都使浏览器无法识别该文件

来自firebug的home.css数据

Date    Sat, 10 Sep 2011 22:31:59 GMT
Server  Apache/2.2.14 (Ubuntu)
X-Powered-By    PHP/5.3.2-1ubuntu4.9
Expires Sat, 17 Sep 2011 22:31:59 GMT
Cache-Control   public
Pragma  no-cache
Etag    e35b61f80bbf8e0dd722c50c65ec6da5
Vary    Accept-Encoding
Content-Encoding    gzip
Content-Length  25163
Keep-Alive  timeout=15, max=92
Connection  Keep-Alive
Content-Type    text/css

编辑:我什至尝试以下也没有用

<?php 
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
 ob_start("ob_gzhandler"); 
else 
ob_start(); 
?>

您需要设置适当的标题 ,以使浏览器将文件识别为已压缩。

但是,对于您的Web服务器而言,这实际上是比代码更好的任务。

尝试这个

<?php
ob_start("ob_gzhandler");
echo file_get_contents("stylesheet.css");
ob_end_flush();
?>

http://php.net/manual/zh/function.ob-gzhandler.php

http://www.php.net/manual/zh/function.ob-end-flush.php

刚刚用apache进行了测试,如果这对您不起作用,那么您会在apache配置中弄乱了某些内容。

标头:

Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:180
Content-Type:text/html
Date:Sat, 10 Sep 2011 23:11:18 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
Vary:Accept-Encoding
X-Powered-By:PHP/5.3.5

暂无
暂无

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

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