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
Alasdair
source share