views:

29

answers:

1

I wanted to compress my pages so I put ob_start('ob_gzhandler'); at the beginning of my php header file. however as I was playing around I noticed it will give me a blank page if I start a session while the ob_gzhandler was not being used! so I did the below and it worked: how ever I'm not sure if this will always use the compression as I imagine their might be a session but the browser will still receive uncompressed data! I guess I would have to restart session if the scenario happens which really shouldnt other than development time. but I guess what I really want to know is some quick tips about zlib and this compression. Is there any performance tips? I assume the server output the internal buffer if there is no indication at end of file but should I put one there? ob_end_flushob_end_clean?ob_end_close? any notes on using memcache with this? any tips and info would be highly appreciated!

+1  A: 

Before ob_gzhandler() compresses the data, it will check to see what type of encoding the browser will accept, if its gzip, or deflate (maybe other things too, im not sure) it will print the output with that compression. All popular browsers are supported and even if you write you own code or are worried about search engine spiders it is up to the HTTP requester to send the correct HTTP header saying that it accepts compressed pages. And no worries, if a browser doesn't support compressed pages this function returns FALSE and no compression is applied.

here is some other stuff From the php man: ob_start This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents. Warning

Some web servers (e.g. Apache) change the working directory of a script when calling the callback function. You can change it back by e.g. chdir(dirname($_SERVER['SCRIPT_FILENAME'])) in the callback function.

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

Again this part is copied from the php manual!

Neo