PHP: Is gzdeflate safe across multiple machines?

后端 未结 1 1815
暗喜
暗喜 2021-01-17 20:39

In the PHP manual there is a comment on gzdeflate saying:

gzcompress produces longer data because it embeds information about the encoding onto the

1条回答
  •  一生所求
    2021-01-17 20:46

    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.

    0 讨论(0)
提交回复
热议问题