Speeding Up the Site by Using PHP GZIP Compression

Compression is a simple way to speed up the site. PHP’s gzip compression is excellent. And using it is very convenient:

Simply put these codes before any HTML content at the beginning of the PHP script:

<?php
  if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
    ob_start("ob_gzhandler");
  else ob_start();
?>

In WordPress, the suitable position for these codes is the beginning of the header.php file of the theme.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *