Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

php - How to enable gzip?

I have found a couple of tutorials on how to enable gzip, but nothing seems to be working for me, so my question is how do i enable gzip. I am on a shared Dreamhost hosting server, It is running PHP version 5.2, and Apache, from the php info i have found this line, maybe this could help?

zlib

ZLib Support    enabled
Stream Wrapper support  compress.zlib://
Stream Filter support   zlib.inflate, zlib.deflate
Compiled Version    1.2.3.3
Linked Version  1.2.3.3

Directive   Local Value Master Value
zlib.output_compression Off Off
zlib.output_compression_level   -1  -1
zlib.output_handler no value    no value

I have also found this line

_SERVER["HTTP_ACCEPT_ENCODING"] gzip, deflate

I don't know if that has anything to do with it. But that is my first question, secondly, i have dropbox, hosting a javscript file, and I am wondering is it possible to have that file gzipped, It is not being transfered compressed, so is ther any way to do so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have you tried with ob_gzhandler?

<?php ob_start("ob_gzhandler"); ?>
<html>
  <body>
    <p>This should be a compressed page.</p>
  </html>
<body>

As an alternative, with the Apache web server, you can add a DEFLATE output filter to your top-level server configuration, or to a .htaccess file:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml 
        text/css application/x-javascript application/javascript
</IfModule>

Tip: Sometimes it is pretty tricky to detect if the web server is sending compressed content or not. This online tool can help with that.

Using the developer tools in my web browser, I tested a PHP file with and without compression to compare the size. In my case, the difference was 1 MB (non-compressed) and 56 KB compressed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...