PHP ob_start () and ob_start ('ob_gzhandler')

What is the difference between using ob_start() and ob_start('ob_gzhandler') ?
How does this affect page speed?

+6
source share
2 answers

This does not affect page speed in the sense you might think.

ob_gzhandler is a callback function that takes content from your output buffer and compresses the data before it exits.

This reduces the size of the content sent to the browser, which can speed up the transfer of content to the client. But it does not speed up your application / website.

+10
source

I needed to force gzip for some administration pages (full of complex HTML tables) that were not automatically compressed for some clients, so I added this method. I'm not sure that I will force it for every page, but at least the admins page is fine.

 function force_gzip() { // Ensures only forced if the Accept-Encoding header contains "gzip" if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) { header('Content-Encoding: gzip'); ob_start('ob_gzhandler'); } } 

950Kb HTML was compressed at around 80KB, resulting in a 5-10-fold increase in speed loading the page.

+4
source

Source: https://habr.com/ru/post/915890/


All Articles