轻量级RESTful PHP服务器 [英] lightweight RESTful PHP server

查看:141
本文介绍了轻量级RESTful PHP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个非常轻量级的PHP服务器来处理来自远程客户端的数据请求。返回的数据是表格式的(类似于从CSV文件或数据库表读取的数据)。 问题是我可能返回潜在的几十万行数据 - 列宽在10 - 15之间(取决于请求的数据类型)。

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

简而言之,返回的数据可能是 HUGE - 为了节省带宽,并提高传输速度,我想压缩数据(也许可以加密它,而我们

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

为了简单起见,假设我正在使用fopen从平面文件读取数据,我可以这样: p>

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
?>

不是很熟悉PHP,有人可以帮我删除这个stub代码更多(特别是当我们通过HTTP头等返回压缩数据(或错误代码)的部分)。

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

最后但并非最不重要的,指出客户端很可能在另一个平台和另一种语言上运行(我将使用C ++编写客户端),所以我想使用PLAIN ASCI文本进行数据传输(与XML非常冗长,需要在另一端解析。)

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

推荐答案

我可能建议您对REST服务器使用ZendFramework。基本约定已经为您实现,这将允许您专注于您的具体要求(数据,文本,压缩等)。

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

这里是参考Zend REST手册页:
http:// framework。 zend.com/manual/en/zend.rest.server.html

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

此外,这篇文章是我在使用Zend REST时的个人经验:
http:// ajcoon .blogspot.com / 2009/09 / rest-services-supporting-xml-and-json.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

即使我使用它来返回XML和JSON,可以轻松地定义自己的视图,为其数据使用不同的编码/格式。

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.

这篇关于轻量级RESTful PHP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆