Speed ​​up your pages--data compression_PHP tutorial

WBOY
Release: 2016-07-20 11:05:48
Original
1100 people have browsed it

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();


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445095.htmlTechArticleMy website is 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 try to compress your own page... (in...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!