cgm225 Posted April 9, 2008 Share Posted April 9, 2008 When should I be using ob_gzhandler? How should I be compressing my scripts? Link to comment https://forums.phpfreaks.com/topic/100349-when-should-i-be-using-ob_gzhandler/ Share on other sites More sharing options...
quiettech Posted April 9, 2008 Share Posted April 9, 2008 When should I be using ob_gzhandler? When you want to send compressed output data to the user browser. How should I be compressing my scripts? It's not the scripts that are compressed. For that you should look at tools like Nu-Coder or eaccelerator (not really compress your scripts, but accelerate processing by caching their precompiled bytecode versions) What you can indeed compress instead is the data that is sent to the user browser. This can be a whole webpage, part of it, or some other content that gets to be interpreted by the browser parsing engine. You do this by using exactly the ob_ family of functions. ob_start() will turn output buffering on. ob_gzhandler() should be passed to it as the first argument - the callback function - when you want the buffer contents to be compressed. This callback function will make sure your buffer contents are compressed according to the user browser specifications, or not compressed at all if the browser doesn't support it. While output buffer is on, all data output (echo, print, and so forth) will not be sent from the script. It will be stored in the buffer. You then use ob_flush() or ob_end_flush(). The first sends the buffer contents (compressed if that was the case) and does not terminate output buffering. The second does the same thing but terminates output buffering, restoring output to its normal mode. Before flushing output, if you want to keep the buffer stored somewhere you should use ob_get_contents(). This will ensure you get the buffer cached in a variable, because flushing the buffer will destroy its contents. In a nutshell, this is it. Link to comment https://forums.phpfreaks.com/topic/100349-when-should-i-be-using-ob_gzhandler/#findComment-513111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.