note 46068 added to ref.zlib
| From: | sit1way at hotmail dot com | Date: | Tue, 28 Sep 2004 14:26:55 +0000 |
| Subject: | note 46068 added to ref.zlib | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77523@lists.php.net to get a copy of this message | ||
Hey all.
I've run into a problem using zlib compression & Apache's ForceType directive.
The problem:
Internet Explorer 6.0+ users are getting a download prompt, the d-loaded file contents being 5k of
compressed data which IE , for some reason, isn't able to interpret/decompress.
I'm running RedHat9 with PHP 4.3.8, Apache 2.0.51, MySql 4.0, & Zlib 1.1.4.
My httpd.conf has Forcetype directive set as follows:
<FilesMatch ^(view)>
ForceType application/x-httpd-php
</FilesMatch
This allows for urls in the format of domain.com/view/var1/var2/ to be evaluated as view.php, &
the vars accessed via script path_info.
My php.ini file has the following zlib settings:
zlib.output_compression = On
zlib.output_compression_level = 6
and my view controller script has the following to send gzip compressed content:
*************************************************
<?
session_start();
/* Start output buffering */
ob_start();
ob_implicit_flush(0);
/* get some content */
php code to get content here
/* Get buffered content */
$contents = ob_get_contents();
ob_end_clean();
/* If browser accepts compression, compress it */
if(ereg("gzip, deflate",$_SERVER['HTTP_ACCEPT_ENCODING'])) {
header("Content-Encoding: gzip");
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
/* Figure out the size and CRC of the original for later */
$Size = strlen($contents);
$Crc = crc32($contents);
/* Compress the data */
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, strlen($contents) - 4);
echo $contents;
function gzip_PrintFourChars($Val) {
for ($i = 0; $i < 4; $i ++) {
echo chr($Val % 256);
$Val = floor($Val / 256);
}
}
/* Output the CRC, then the size of the original */
gzip_PrintFourChars($Crc);
gzip_PrintFourChars($Size);
}
else { echo $contents; }
*************************************************
In other browsers (e.g. Mozilla, Opera, etc.), the forcetype/zlib combo works flawlessly; however,
IE, still unfortunately the major player in browser market, is screwing up something, or I'm
doing something wrong on my end -- I just don't know what that might be!
If anyone has encountered this issue, please, please let me know. I don't want to drop zlib,
it's way to useful an extension to drop....
TIA,
--Noah
----
Manual Page -- http://www.php.net/manual/en/ref.zlib.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46068
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46068&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46068&report=yes
Search -- http://master.php.net/manage/user-notes.php