note 88044 added to function.gzcompress
| From: | Samnan at osu1 dot php dot net | Date: | Wed, 07 Jan 2009 14:34:47 +0000 |
| Subject: | note 88044 added to function.gzcompress | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148921@lists.php.net to get a copy of this message | ||
To properly use gzcompress to send compressed data to browsers that support it (most of modern
browsers do, even mobile ones !), use this function (I dont think W3C validator issue mentioned
earlier is valid ). use ob_start() at start of your script also
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();
}
----
Server IP: 69.147.83.197
Probable Submitter: 202.61.44.25
----
Manual Page -- http://www.php.net/manual/en/function.gzcompress.php
Edit -- https://master.php.net/note/edit/88044
Del: integrated -- https://master.php.net/note/delete/88044/integrated
Del: useless -- https://master.php.net/note/delete/88044/useless
Del: bad code -- https://master.php.net/note/delete/88044/bad+code
Del: spam -- https://master.php.net/note/delete/88044/spam
Del: non-english -- https://master.php.net/note/delete/88044/non-english
Del: in docs -- https://master.php.net/note/delete/88044/in+docs
Del: other reasons-- https://master.php.net/note/delete/88044
Reject -- https://master.php.net/note/reject/88044
Search -- https://master.php.net/manage/user-notes.php