PHP: Is gzdeflate safe for multiple machines?

The PHP manual has a comment on gzdeflate:

gzcompress produces longer data because it contains information about encoding per line. If you are compressing data that will only ever be processed on one machine, then you do not need to worry about which of these functions you use. However, if you are passing data compressed by these functions to another machine, you should use gzcompress.

and then

Performing 50,000 repetitions of different content, I found that gzdeflate () and gzcompress () performed equally fast, regardless of content and compression level, but gzinflate () was always about twice as fast as gzuncompress ().

For my purpose, I archive data on a machine for future use. Data is read frequently, but only recorded once. Theoretically, one day it will be transferred to another machine, if at some point I will change the servers, but this is in a few years.

Is it safe for me to use gzdeflate and gzinflate as opposed to gzcompress and gzuncompress?

My thinking is as follows: gzinflate is faster, and this will help the server a lot, as there will be many read requests. If at some point in the future I can’t read the file, then I can figure out how to unzip the file and recompress it, right? It's not that gzinflate will simply not magically work one day, as the first comment seems to be. Even the lack of a 6-byte header, I'm sure it will expand in some way.

Thoughts?

UPDATE - Benchmark

10,000 iterations each:

gzdeflate took 19.158888816833 seconds and size 18521 gzinflate took 1.4803981781006 seconds gzcompress took 19.376484870911 seconds and size 18527 gzuncompress took 1.6339199542999 seconds gzencode took 20.015944004059 seconds and size 18539 gzdecodetook 1.8822891712189 seconds 
+7
source share
1 answer

Comment nonsense. You can use any of gzcompress , gzdeflate or gzencode to create compressed data that you can transfer anywhere. These functions differ only in the wrapper around deflation data (RFC 1951). gzcompress has a zlib wrapper (RFC 1950), gzdeflate does not have a wrapper, and gzencode has a gzip wrapper (RFC 1952).

I would recommend not using gzdeflate , since no wrapper means integrity checking. gzdeflate should be used only when some other shell is generated outside of this, for example. for zip files that also use the deflate format. The speed comment is almost certainly incorrect. Checking the integrity of gzuncompress() takes very little time compared to decompression. You have to do your own tests.

From this one example, I can be overgeneralizing, but I would say that you should completely ignore comments in the PHP documentation. They are to be generous, ignorant.

By the way, these functions are named in a terribly confusing way. Only gzencode should have " gz " in the name, as this is the only one that actually deals with the .gz format. gzcompress sounds like it is compressed in gzip format, but in fact it is compressed in zlib format.

+9
source

All Articles