【发布时间】:2010-12-13 21:27:56
【问题描述】:
我正在编写一个将数据作为响应发送给客户端的服务。
我正在发送文本(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 使用哪些语句吗?
【问题讨论】:
-
您希望您的数据像在 ZIP 存档中一样被压缩,还是只是为了传输而压缩?
-
Gumbo:只是为了传输而压缩(数据已经作为字符串从数据库读取到内存中 - 格式如上面的伪代码所示)
标签: php encryption compression http-headers http-compression