In the PHP manual there is a comment on gzdeflate saying:
gzcompress produces longer data because it embeds information about the encoding onto the
The comment is nonsense. You can use any of gzcompress
, gzdeflate
, or gzencode
to produce compressed data that can be portably decompressed anywhere. Those functions only differ in the wrapper around the deflate data (RFC 1951). gzcompress
has a zlib wrapper (RFC 1950), gzdeflate
has no wrapper, and gzencode
has a gzip wrapper (RFC 1952).
I would recommend not using gzdeflate
, since no wrapper means no integrity check. gzdeflate
should only be used when some other wrapper is being generated outside of that, e.g. for zip files, which also use the deflate format. The comment about speed is almost certainly false. The integrity check of gzuncompress()
takes very little time compared to the decompression. You should do your own tests.
From this one example I might be overgeneralizing, but I would say that you should completely ignore the comments in the PHP documentation. They are, to be generous, uninformed.
By the way, these functions are named in a horribly confusing way. Only gzencode
should have "gz
" in the name, since that is the only one of those that actually deals in the .gz
format. gzcompress
sounds like it compresses to the gzip format, but in fact it compresses to the zlib format.