PHP:gzdeflate在多台机器上是否安全? [英] PHP: Is gzdeflate safe across multiple machines?

查看:207
本文介绍了PHP:gzdeflate在多台机器上是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP手册中有对gzdeflate的评论:

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


gzcompress生成更长的数据,因为它嵌入了关于
的信息对字符串进行编码。如果你正在压缩数据,
只能在一台机器上处理,那么你不需要担心
你使用这些函数。但是,如果您将使用这些函数压缩的
数据传递到不同的机器,则应该使用gzcompress

gzcompress produces longer data because it embeds information about the encoding onto the string. If you are compressing data that will only ever be handled on one machine, then you don't need to worry about which of these functions you use. However, if you are passing data compressed with these functions to a different machine you should use gzcompress.

然后


在各种内容上运行50000次重复,我发现gzdeflate()
和gzcompress()不管内容和
的压缩级别,但gzinflate()总是大约是
gzuncompress()的两倍。

running 50000 repetitions on various content, i found that gzdeflate() and gzcompress() both performed equally fast regardless content and compression level, but gzinflate() was always about twice as fast as gzuncompress().

出于我的目的,我将数据存档在机器上以备将来使用。数据经常读取,但只写入一次。在理论上,如果我在某一时刻更换服务器,那么它有一天会被移动到另一台机器上,但是这是在路上几年。

For my purpose I am archiving data on a machine for future use. The data is read often, but written only once. In theory it will one day be moved onto another machine, if I change servers at some point, but that is a few years down the road.

对我来说是安全的使用gzdeflate和gzinflate而不是gzcompress和gzuncompress?

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

我的想法如下:gzinflate更快,这将有助于服务器很多,因为会有很多读取请求。如果在将来的某个时候,我无法读取文件,那么我应该能够找出如何解压缩文件并重新压缩它,对吧?这不是gzinflate将只是神奇地不工作一天,像第一个评论似乎在说。

My thinking is as follows: gzinflate is faster and this will help the server a lot since there will be lots of read requests. If at some point in the future I can't read the file then I should be able to figure out how to decompress the file and recompress it, right? It is not that the gzinflate will just magically not work one day, like the first comment appears to be saying. Even missing a 6 byte header I'm sure that it'll be expandable somehow.

想法?

更新 - 基准

每次10,000次迭代:

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


推荐答案

注释是废话。您可以使用 gzcompress gzdeflate gzencode 以产生可在任何地方可移植地解压缩的压缩数据。这些函数只在缩写数据(RFC 1951)的包装器中有所不同。 gzcompress 有一个zlib包装器(RFC 1950), gzdeflate 没有包装器, gzencode 有一个gzip包装器(RFC 1952)。

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).

我建议不要使用 gzdeflate ,因为没有包装器意味着没有完整性检查。 gzdeflate 只应在其他外部生成其他包装时使用。对于zip文件,这也使用deflate格式。关于速度的评论几乎肯定是假的。与解压缩相比, gzuncompress()的完整性检查花费的时间非常少。你应该自己做测试。

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.

从这个例子中我可能是overgeneralizing,但我会说,你应该完全忽略PHP文档中的注释。他们是大方,不知情的。

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.

顺便说一句,这些函数以一个可怕的混乱的方式命名。只有 gzencode 在名称中应该有 gz ,因为这是唯一一个在 .gz 格式。 gzcompress 听起来像是压缩为gzip格式,但实际上它压缩为zlib格式。

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.

这篇关于PHP:gzdeflate在多台机器上是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆