What is the difference between using ob_start()
and ob_start('ob_gzhandler')
?
How does it affect the page speed ?
Asked
Active
Viewed 1.6k times
12

Sithu
- 4,752
- 9
- 64
- 110
2 Answers
16
This doesn't affect page speed in the sense you'd might think.
the ob_gzhandler is a callback function which takes the contents from your output buffer and compresses the data before outputting it.
This reduces the size of the content being sent to the browser which might speed up the content transfer to the client. But it doesn't speed up your application/website.

Repox
- 15,015
- 8
- 54
- 79
-
If a page uses ob_start('ob_gzhandler') which speeds up the content transfer to the client, I think this buffering may speed up that page rendering as well. – Sithu May 16 '12 at 09:19
-
2Those two things is not related to eachother. Page rendering depends on the clients hardware. It doesn't matter if I can have the content in 1 second if rendering the content takes 3 seconds. You still have to fetch the content before you can render anything. – Repox May 16 '12 at 09:23
6
I needed to force gzip for some admin pages (full of complicated HTML tables) that weren't being automatically compressed for some clients so I added this method. I'm not sure I would force it for every page, but at least the admin pages its 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 of HTML was compressed down around 80KB resulting in a 5-10x speed increasing loading the page.

Nick Bedford
- 4,365
- 30
- 36