I want to write an extremely lightweight PHP server which handles data requests from remote clients. The data returned is tabular (like that of data read from a CSV file or a database table). The "problem" is that I could be returning potentially several hundred thousand rows of data - with a column width of between 10 - 15 (depending on the type of data requested).
In short, the data returned could be HUGE - and in an attempt to save bandwidth, and also increase the speed of transmission, I would like to compress the data (maybe optionally encrypt it whilst we are at it) before sending it backto the client.
I am at a loss as to how to write the server side script to handle the request (and send the data or error code back).
For the sake of simplicity, lets assume that I am reading the data from a flat file, using fopen, I could have something like this:
<?php
// extract request variables and determine action required based on REQUEST params
// handle request (fetch requested data)
// if no error then return compressed (and encrypted?) data
// else if error return error code
?>
Not being very familiar with PHP, could someone please help me with "fleshing out" this stub code a little bit more (particularly the part when we are returning the compressed data (or error code) via HTTP headers etc)?.
Last but not the least, I have to point out that the client is likely to be running on another platform and another language (I will be writing the client in C++), so I would like to use PLAIN ASCI text for the data transfer (as opposed to XML which is very verbose and requires parsing at the other end).