Over a million developers have joined DZone.

Enabling Zip Compression With PHP

·
// 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();
}
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}