php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #6481 Gzcompress
Submitted: 2000-09-01 11:07 UTC Modified: 2001-01-22 21:32 UTC
From: wico at cnh dot nl Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0 Latest CVS (01/09/2000) OS: linux
Private report: No CVE-ID: None
 [2000-09-01 11:07 UTC] wico at cnh dot nl
Hiya

I want to compress webpages for clients that support it

$data is a whole html page
but:

This works:

function Compress ($data) {
	$fp = fopen("/tmp/tempje", "w");
	fputs($fp, $data);
	fclose($fp);
	$data2 = `cat /tmp/tempje |/usr/bin/gzip -f`; */
	Header("Content-Type: text/html");
	Header("Content-Encoding: gzip");
	echo($data2);
}

this doesn't:

function Compress ($data) {
	$data = gzcompress($data);
	Header("Content-Type: text/html");
	Header("Content-Encoding: gzip");
	echo($data2);
}

Anyone can explain this?

Greetz,

Wico

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-03 06:02 UTC] stas@php.net
That's easy - you don't define data2 in second function.
 [2000-09-04 03:33 UTC] wico at cnh dot nl
Hiya

As i allready said in my email thats a typo.

This works:

function Compress ($data) {
	$fp = fopen("/tmp/tempje", "w");
	fputs($fp, $data);
	fclose($fp);
	$data2 = `cat /tmp/tempje |/usr/bin/gzip -f`; 
	Header("Content-Type: text/html");
	Header("Content-Encoding: gzip");
	echo($data2);
}

this doesn't:

function Compress ($data) {
	$data = gzcompress($data);
	Header("Content-Type: text/html");
	Header("Content-Encoding: gzip");
	echo($data);
}



 [2000-09-20 16:08 UTC] wico at cnh dot nl
Subject: gzcompress() broken
To: wico@cnh.nl 

I was checking out http://bugs.php.net/bugs.php?id=6481 and found out why you are right.  :-)

The rest of the functions in the zlib section all use gzip compression.  gzcompress() and gzuncompress() do not -- they use a deflate style compression, if I remember right.  To fix it, you need to edit the zlib files in PHP to call the correct zlib function.

It would be nice if you added this information for me (I have no desire to make a PHP bug reporting account) and if you moved it to the zlib section instead of a general question.

-- 
Tyler Akins                    tyler@boas.anthro.mnsu.edu

 [2000-09-20 16:11 UTC] wico at cnh dot nl
Move to the rigth bug section

P.S. can someone please take a look a this bug, my programm depends on it

Greetz,

Wico
 [2000-09-23 22:21 UTC] stas@php.net
I guess you should use gzopen("php://stdout","w") instead, because gzcompress doesn't have all gzip file headers too.
In other words, gzcompress and gzopen/gzwrite are different functions, and in zlib too.
 [2000-09-26 23:56 UTC] wico at cnh dot nl
I realy think this should be in the manual (where you can find it easly), but also should have a fix/workaround
(i opened it again because i realy think this should be fixed, and that stuff about the crc doesn't look verry right to me either)

Greetz, tnx,

Wico

this did i got from Tyler Akins (thx for your effort and support)

Remember when I told you why gzcompress() doesn't work as it should if you
want to output compressed data?

[ I wrote ]
> I was checking out http://bugs.php.net/bugs.php?id=6481 and found out
> why you are right.  :-)

Anyway, I wrote a lengthy note on the PHP page explaining how to get it to 
work properly for outputting compressed data to the client.  You might want to 
check it out.

    http://www.php.net/manual/function.gzcompress.php

Basically, it doesn't output the gzip header, it doesn't output a proper CRC, 
and it certainly doesn't add the size field.  For more information on 
gzip-style files, check out

    http://swrinde.nde.swri.edu.pub/png/documents/zlib/rfc-gzip.html

Hope this helps.  Actually this information would probably be really nice to 
put in the bug report.

-- 
Tyler Akins                    tyler@boas.anthro.mnsu.edu

 [2000-10-11 09:36 UTC] stas@php.net
See also #7033
 [2001-01-22 21:32 UTC] jimw@php.net
now makes clear it does deflate compression. (examples would probably work with Content-Encoding: deflate specified for browsers that support deflate in addition to gzip.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 04:01:30 2024 UTC