Forum Moderators: coopster

Message Too Old, No Replies

problems using zlib, gzip (htaccess file)?

         

dinbrca

11:03 pm on Jul 29, 2010 (gmt 0)

10+ Year Member



from what i understand:
"using zlib.output_compression is preferred over ob_gzhandler()"
i used ob_gzhandler() in my website but i want to have more options and more compression on my website..
so i started to read a little about enabling zlib using my HTAccess file.. this is my current htaccess file:

ErrorDocument 404 /ron/404error.php

and yes i check it and it does work (means i can add htaccess to my hosting)..

this is what i get when i use phpinfo() function on my server:
php version: 4.4.9
ZLib
ZLib Support: enabled
Compiled Version: 1.1.4
Linked Version: 1.2.3
zlib.output_compression: Off
zlib.output_compression_level: -1
zlib.output_handler: no value
HTTP_ACCEPT_ENCODING: gzip,deflate
HTTP_ACCEPT_LANGUAGE: en-us,en;q=0.5

what i want is to add a gzip compression with level 2 to all files on my website (including all images, css, html, php, js files)
so from what i understan i need to add this to my htaccess:
zlib.output_compression = On
zlib.output_compression_level = 2
but when i add this to the htaccess i get this problem:
[img842.imageshack.us...]
also does this code works for all files?

SevenCubed

11:46 pm on Jul 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are using it in an htaccess file then something like this is probably what you are looking for...

<FilesMatch "\.(php|css|html|xml|txt|js)$">
SetOutputFilter DEFLATE
</FilesMatch>

You will need to make sure Apache mod_deflate is enabled. And, DO NOT ADD IMAGES or PDF's to the compression because they are already compressed. If you add them they may actually take longer to load.

BillyS

1:30 am on Jul 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



dinbrca -

Do you have mod_deflate?

Also, whatever you do, test this change in several browsers. When I went through this tweaking process, I found that I was double compressing files in Opera and I was losing that traffic.

If the above solution doesn't work, sticky me and I will post a second solution (the one that worked for me.)

dinbrca

11:19 am on Jul 30, 2010 (gmt 0)

10+ Year Member



what i have in _SERVER["HTTP_ACCEPT_ENCODING"] is:
gzip,deflate
so i do have deflate but from what i understand gzip is much more powerful.. and also i want to choose my compress level.. and make it compressed level = 2..
thank you for answering my questions

dinbrca

12:45 pm on Jul 30, 2010 (gmt 0)

10+ Year Member



BY THE WAY- SevenCubed, i get the same error when i use the code you brought me this is pretty weird..
and heres my php info:
[site-4me.com...]

BillyS

2:23 pm on Jul 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



dinbrca - I see the problem but it looks like you want to work this through with SevenCubed. I'm sure he'll see it too.

Best of luck with this one. I'll unflag this thread on my end.

SevenCubed

3:23 pm on Jul 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...from what i understand gzip is much more powerful...


gzip is really just the older version of deflate, I checked the response header to determine what version of Apache you are on but the server signature is off so it wouldn't cough it up.

Also I need to clarify something here. I may be wrong but it looks like you tried to put php scripting directly into your .htaccess file? .htaccess is reserved strictly for Apache directives.

The example I provided is the only way that I know that works. I have it implemented on various sites on various servers and it works so I don't know what's up with your configuration.

Someone else will probably jump in here with a fresh perspective to help you solve it.

penders

5:19 pm on Jul 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what i have in _SERVER["HTTP_ACCEPT_ENCODING"] is:
gzip,deflate ... so i do have deflate


This is what the browser is sending to the server. Telling the server what it is capable of receiving. Not what the server is capable of sending. Are you sure the server can send this encoding? (Pretty much every modern browser is capable of receiving compressed content these days and sends this information in the header.)

dinbrca

7:25 pm on Jul 30, 2010 (gmt 0)

10+ Year Member



i am not sure of anything..
this is not my host, i got it from a girlfriend of a brother of my friend and she got it from another guy.. so i know nothing but i think that phpinfo() gives enough info.. so i gave a link to my phpinfo() which is this:
[site-4me.com...]
by the way BillyS i dont mind that you will help me.. as long as i get my apache server to send my website gzipped currectly on level 1 or 2..
penders- i am sure i can send files encoded as gzipped because i added this line to the top of my website:
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
and than i checked if my website did compressed using the gzip test:
[gidnetwork.com...]

SevenCubed

8:19 pm on Jul 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You appear to be trying to compress things from 2 points -- through php code directly in a page and then again through an Apache .htaccess directive. That may be causing a conflict. Maybe try one or the other but not both. I can't help you with the php version because I prefer letting Apache handle the compression.

If you can, try removing the php compression code from a single page and allow Apache to handle it based on what I offered as a solution up top. Barring that -- I can't think of anything else.

Alcoholico

8:55 pm on Jul 30, 2010 (gmt 0)

10+ Year Member



Try using the next two lines in your .htaccess file:

php_flag zlib.output_compression on
php_flag zlib.output_compression_level 2


That should compress text files processed by php, depending on your server configuration, most likely only .php files, as someone mentioned before, apache deflate module is the preferred way to compress every text file on the fly, text file means not only .txt but also .htm*, .js, .css and the most common .php

BillyS

12:05 am on Jul 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is torture. I noticed this in your php file...

<ADDRESS>Apache/1.3.33 Server at site-4me.com Port 80</ADDRESS>

It appears that you're runnig Apache 1.3, so it's doubtful mod_deflate will ever work. I believe it only works on Apache 2.0. Aloholico's solution might work, it didn't for me... If you're going to compress via htaccess, remove this line from your template:

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

Or you will wind up with the double compression problem I mentioned earlier. I'm pretty sure the below will work, but it will not compress your .css file. One problem at a time.

<ifModule mod_php4.c>
php_value zlib.output_compression 16386
</ifModule>