My website has been getting slower and slower recently, not because of the slow script execution time, but because of the slow network transmission speed.
I know that http1.1 supports gzip-encoded data, so I try to compress my own page...
(It can be set in php.ini to directly output gzip encoding, but I haven’t tried it)
I found a gzdoc.php online and modified it so that everyone can ponder it together.
ob_start();//Open output buffer
ob_implicit_flush(0);//
//*****************************************************************//
// Function name: canGzip()
//Function: Check whether the client browser supports gzip, x-gzip encoding
//Parameters:
//Return value: Supported encoding type "gzip", "x -gzip", returning false means that
//*****************************************************************//
function canGzip()
{
//if (headers_sent() || connection_status)
//return false;
if (strpos('King'.$_SERVER["HTTP_ACCEPT_ENCODING"], 'gzip') !== false)
return "gzip";
if (strpos('King'.$_SERVER["HTTP_ACCEPT_ENCODING"], 'x-gzip') !== false)
return "x-gzip";
return false;
}
//*****************************************************************//
//Function name: doGzipOut($level, $debug)
//Function: Compress and output the output buffered data
//Parameter: $level represents the compression level, 0 = no compression, 9 = maximum compression rate
// $debug represents whether to output debugging information, 1 = output, 0 = no output
//return value:
//*****************************************************************//
function doGzipOut($level = 1, $debug = 0)
{
$ENCODING = canGzip();
if ($ENCODING )
{
echo "nn";
$contents = ob_get_contents();