Discuss how to enable gzip page compression in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:07:38
Original
726 people have browsed it

Example 1 (using PHP’s built-in compression function):

Copy code The code is as follows:

if(Extension_Loaded('zlib')) Ob_Start('ob_gzhandler');
Header("Content-type: text/html");
?>




Untitled Document


for($i=0;$i<10000;$i++){
echo 'Hello World!';
}
?>


if(Extension_Loaded('zlib')) Ob_End_Flush();
?>

Example 2 (from Write function):
Copy code The code is as follows:






Untitled Document


< ;/body>

ob_end_flush();
//Compression function
function ob_gzip($content){
if(!headers_sent ()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")){
$content = gzencode($content,9);
header("Content-Encoding: gzip" );
header("Vary: Accept-Encoding");
header("Content-Length: ".strlen($content));
}
return $content;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327532.htmlTechArticleExample 1 (using PHP’s built-in compression function): Copy the code as follows: ?PHP if(Extension_Loaded('zlib ')) Ob_Start('ob_gzhandler'); Header("Content-type: text/html"); ? !DOCTYPE h...
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