views:

425

answers:

1

I'm writing a little analysis page which will help me hunt down bugs in an application. In essence it allows to visually compare actual data and log entries, plus perform a bit of analysis on the data.

Since this is for debugging only and since I will be deploying this on the live site I want it to have as little server load as possible. Several of the analysis options will include rather heavy substring searching or n2 operations, so I'm going to offload this to the client.

This means that the PHP page will just take the data from the tables and logs, JSON some of it, and write it out. The client Javascript will then do all the analysis etc.

The problem is that the JSON'ed data will be several MB large, and my connection to the server - slow. It would be nice to compress the data somehow. Anyone have ideas?

The environment is PHP + Apache; I don't know if mod_gzip will be installed; and I have no control over it.

+7  A: 

You can compress the data with PHP’s output control. Just put this call at the start of your script before any output:

ob_start('ob_gzhandler');

Now any output will be compressed with either gzip or deflate if accepted by the client.

Gumbo
Fixed o_start to ob_start.
Tatu Ulmanen
It worketh! Hooray! :)
Vilx-
+1 -- definitely the way to go. Note, however, that PHP must be configured with --with-zlib for this to work http://us2.php.net/manual/en/zlib.installation.php
Frank Farmer