Accelerate Your page-data compression-PHP Tutorial

Source: Internet
Author: User
Accelerate Your page-data compression. Recently, even websites are getting slower and slower, not because the script execution time is slow, but the network transmission speed is slow. I know that http1.1 supports gzip-encoded data, so try to compress your page... (recently, my website is getting slower and slower, not because of slow script execution, but network transmission speed.
I know that http1.1 supports gzip encoding data, so try to compress your page...
(You can set it in php. ini and output it as gzip code directly, but you have not tried it)

I found a gzdoc. php on the Internet and changed it so that everyone could think about it.
Ob_start (); // enable the output buffer.
Ob_implicit_flush (0 );//

//************************************** ***************************//
// Function name: canGzip ()
// Purpose: Check whether the client browser supports gzip and x-gzip encoding.
// Parameters:
// Return value: Supported encoding types: "gzip" and "x-gzip". false indicates not supported.
//************************************** ***************************//
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 buffered data.
// Parameter: $ level indicates the compression level, 0 = no compression, 9 = maximum compression rate
// $ Debug indicates whether to output debugging information. 1 = output, 0 = no output.
// Return value:
//************************************** ***************************//
Function doGzipOut ($ level = 1, $ debug = 0)
{
$ ENCODING = canGzip ();
If ($ ENCODING)
{
Echo "n N ";
$ Contents = ob_get_contents ();


Bytes. Http1.1 supports gzip data, so try to compress your page...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.