Home > Backend Development > PHP Tutorial > PHP output gzip compression

PHP output gzip compression

WBOY
Release: 2016-07-29 09:01:12
Original
1276 people have browsed it

<code><span><span>function</span><span>ob_gzip</span><span>(<span>$content</span>)</span>{</span><span>if</span>(!headers_sent()&&extension_loaded(<span>"zlib"</span>)&&strstr(<span>$_SERVER</span>[<span>"HTTP_ACCEPT_ENCODING"</span>],<span>"gzip"</span>)){
        <span>$content</span> = gzencode(<span>$content</span>,<span>9</span>);
        header(<span>"Content-Encoding: gzip"</span>);
        header(<span>"Vary: Accept-Encoding"</span>);
        header(<span>"Content-Length: "</span>.strlen(<span>$content</span>));
    }
    <span>return</span><span>$content</span>;
}
ob_start(<span>'ob_gzip'</span>); <span>//函数名</span><span>echo</span><span>"这是测试字符串这是测试字符串这是测试字符串"</span>;
ob_end_flush();</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces PHP output gzip compression, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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