Compress gzip string

2019-07-23 02:33发布

问题:

I want to compress a string in PHP and write it to a file without using the gzwrite function as I want to store the actual compressed string in a database first, but I am unsure as whether to use gzcompress, gzencode or gzdeflate as it's not very clear.

Any ideas?

  • Edit: the already compressed string will be written into a *.gz file from the database so it has to be compatible.

回答1:

Use gzcompress if you just want to compress the string. gzencode will also add gzip file headers so it can be uncompressed directly by gzip and similar tools.

gzdeflate uses the deflate algorithm which is very similar to the first one.

I think yo want to use gzencode in ths case since the data is going to be stored as a file.