关于 PHP 和 gz 压缩
我在 PHP 中寻找 gz-compression,发现了这段代码:
<?php
function print_gzipped_output()
{
$HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"];
if( headers_sent() )
$encoding = false;
else if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false )
$encoding = 'x-gzip';
else if( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false )
$encoding = 'gzip';
else
$encoding = false;
if( $encoding ) {
$contents = ob_get_clean();
$_temp1 = strlen($contents);
if ($_temp1 < 2048) // no need to waste resources in compressing very little data
print($contents);
else
{
header('Content-Encoding: '.$encoding);
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, $_temp1);
print($contents);
}
}
else
ob_end_flush();
}
?>
我的问题很简单:该行
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
实际上意味着什么?
先感谢您
I was looking for gz-compression in PHP and I found this piece of code:
<?php
function print_gzipped_output()
{
$HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"];
if( headers_sent() )
$encoding = false;
else if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false )
$encoding = 'x-gzip';
else if( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false )
$encoding = 'gzip';
else
$encoding = false;
if( $encoding ) {
$contents = ob_get_clean();
$_temp1 = strlen($contents);
if ($_temp1 < 2048) // no need to waste resources in compressing very little data
print($contents);
else
{
header('Content-Encoding: '.$encoding);
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, $_temp1);
print($contents);
}
}
else
ob_end_flush();
}
?>
My question is simple: what does the line
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
actually means?
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 gzip 格式文件的标头。您可以在此处查看更多详细信息。
前两个字节将文件标识为 gzip 压缩的。下面的
8
指定了DEFLATE
压缩方法的使用。最后四个零字节用于不需要的字段。This is the header for gzip-format files. You can view more details here.
The first two bytes identify the file as gzipped. The following
8
specifies the use of theDEFLATE
compression method. The final four zero bytes are for fields which aren't needed.