gzencode 默认使用ZLIB_ENCODING_GZIP编码,使用gzip压缩格式,实际上是使用defalte 算法压缩数据,然后加上文件头和adler32校验
gzdeflate 默认使用ZLIB_ENCODING_RAW编码方式,使用deflate数据压缩算法,实际上是先用 LZ77 压缩,然后用霍夫曼编码压缩 gzcompress ;默认使用ZLIB_ENCODING_DEFLATE编码,使用zlib压缩格式,实际上是用 deflate 压缩数据,然后加上 zlib 头和 CRC 校验
php 代码
';echo'gzcompress';echo'';echo $m = base64_encode(gzcompress($a));echo'';echo'$m的长度:'.strlen($m);echo "";echo 'gzdeflate';echo '';echo $m=base64_encode(gzdeflate($a));echo '';echo '$m的长度:'.strlen($m);echo'';echo'gzencode';echo'';echo $m = base64_encode(gzencode($a));echo'';echo'$m的长度:'.strlen($m);
a的长度:927gzcompresseJxVU9l22kAM/ZV8Xt/ac/oDY0yCIaFgNpdkErYsrQ/gJDgBL8DHdDTLU3+ho5mJQ1905KuRdHUls10bHvZ/iMdfZ3zwDsGz82nzv89hwO+o9VlBWBZUCHRCNRhrh+3acnZlHV7MeL3j/J8JHIJTRCwfqxBfLaDvYZ37F05vHE5+WAd6l9j0fI52tNJWxZG2Yppiyi0WFH7tDMNvHjRydPK5czRvfwN+h+1Wn1OdItFUJivTyTRoDlh+4SZ59FiGwyvfU9H2zBCM4Tl0vO5jGfQ4bWMabUNrBtu14z6cc28lCiRopVLL0obY4Qhr6iqMKF9iV3lscDoxIBYXv3NxXTeD1rB4ayiTJkbzjiWnrg+CGlXeYplmqvfiCgY9sY4qenqrf8srnOSDp8XZjvDp1oZ4ccnf3SosjmW9Licjo27IctQRglxEbjMynch0wYrCCXIbni7ZnpK2ViidqMrCPHhQDeSgcX0v2KU+kU9Nm4gipHEljijGbBfLJOWbocklopbZc1P+Xm/RgC3Y9x2lYwPON3bBurVMn5xKg1/ojNus2H7K8iE7Tzx3jN0LfRNm/X0oia7mHmev0CCIkxjCja2pIjP4LOSjcQVC1zebyjCrJC6dlO7noLg+aC1kinzgsGZHHO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c3FdN4PWsHhrKJMmRvOOJaeuD4IaVd5imWaq9+IKBj2xjip6eqt/yyuc5IOnxdmO8OnWhnhxyd/dKiyOZb0uJyOjbshy1BGCXERuMzKdyHTBisIJchueLtmekrZWKJ2oysI8eFAN5KBxfS/YpT6RT02biCKkcSWOKMZsF8sk5ZuhySWiltlzU/5eb9GALdj3HaVjA843dsG6tUyfnEqDX+iM26zYfsryITtPPHeM3Qt9E2b9fSiJruYeZ6/QIIiTGMKNrakiM/gs5KNxBULXN5vKMKskLp2U7ueguD5oLWSKfOCwZkcc4fuXr98wv0ZkshVT8wvc+UAP7iaGeNv/AC8zReSfAwAA$m的长度:700
这三个函数的比较实质上是三种压缩方法:deflate, zlib, gzip的比较。
从性能的维度看:deflate 好于 gzip 好于 zlib从文本文件默认压缩率压缩后体积的维度看:deflate 好于 zlib 好于 gzip