3

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

1
  • Just a side note that compression is really much better handled by your web server. Commented Dec 25, 2011 at 5:32

1 Answer 1

3

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 the DEFLATE compression method. The final four zero bytes are for fields which aren't needed.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.