我正在编写一个将数据作为响应发送给客户端的服务。
我正在发送文本(PLAIN ASCII)数据,但我想先压缩数据(使用任何标准压缩例程),然后使用 header() 函数等将压缩数据发送回服务器。
我对 PHP 比较陌生,所以收集了数据后,我知道需要知道如何将(压缩的)数据以 HTTP 响应发送给用户
这是我到目前为止的伪代码:
<?php
function createResponse($args)
{
if ( ($data = fetch_data($args)) !== NULL)
{
/* Assumption is that $data is a string consisting of comma separated
values (for the columns) and each "row" is separated by a CRLF
so $data looks like this:
18-Oct-2009, 100.2, -10.5, 15.66, 34.2, 99.2, 88.2, 'c', 'it1', 1000342\r\n
19-Oct-2009, -33.72, 47.5, 24.76, 8.2, 89.2, 88.2, 'c', 'it2', 304342\r\n
etc ..
*/
//1. OPTIONAL - need to encrypt $data here (how?)
//2. Need to compress (encrypted?) $data here (how?)
//3. Need to send HTTP Status 200 OK and mime/type (zip/compressed here)
//4. Need to send data
}
else
{
//5. Need to send HTTP error code (say 404) here
}
}
?>
任何有经验的 PHP 编码员都可以告诉我上面的 1 -5 使用哪些语句吗?