views:

257

answers:

2

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).

+1  A: 

Hello,

I might suggest that you use the ZendFramework for your REST server. The basic conventions have already been implemented for you, and this will allow you to focus on your specific requirements (data, text, compression, etc).

Here is the reference manual page for Zend REST: http://framework.zend.com/manual/en/zend.rest.server.html

Also, here's a blog post I wrote in my personal experience with using Zend REST: http://ajcoon.blogspot.com/2009/09/rest-services-supporting-xml-and-json.html

Even though I used it to return XML and JSON, one could easily define their own view that uses a different encoding/format for their data.

AJ
A: 

Here's a possibility to consider: Upload the table of data to Amazon SimpleDB, and then use this: http://blog.webservius.com/2010/09/14/introducing-amazon-simpledb-integration/ (It automatically turns any SimpleDB table into a full-featured REST API complete with JSON support, developer signup page, etc, etc...)

Eugene Osovetsky