DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Enabling Zip Compression With PHP

01.03.2006
| 5048 views |
  • submit to reddit
        // if you want to reduce the bandwidth bill and increase page load time for long pages - this PHP snippet will turn on gzip compression for those that support it.

function compress_handler($in_output)
{
  return gzencode($in_output);
}
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== FALSE)
{
  ob_start('compress_handler');
  header('Content-Encoding: gzip');
}
else
{
  ob_start();
}