好的,有人编写了Last.FM API的PHP实现,我正在将其用于我的一个小项目。他的实现不需要从Last.FM服务器获取压缩数据,因此我决定修改他的实现以与gzip配合使用以减少带宽。我在请求压缩数据时没有问题,它工作得很好,并且所有数据都经过压缩(检查)。问题是将其解码。我对PHP很陌生,最近两天我一直在尝试对其进行解码,但是没有任何尝试。 :D
这是请求和接收数据的功能。如果有人可以帮助我使此函数解码数据,我将非常感激。
function send ($msg) {
// Send message over connection
fwrite($this->handle, $msg);
$response = array();
$line_num = 0;
while ( !feof($this->handle) ) {
$response[$line_num] = fgets($this->handle, 4096);
$line_num++;
}
// Return response as array
return $response;
}
$ this-> handle在哪里
$this->handle = fsockopen($this->host, $this->port, $this->error_number, $this->error_string);
谢谢=)
最佳答案
您是否尝试过类似...
$response='';
while(!feof($this->handle)) {
$response.=fgets($this->handle, 4096);
}
$response=gzdecode($response);
return explode("\n",$response);
我假设整个响应被压缩,而不是每行单独显示。如果是每一行,则只需将fgets()更改为gzdecode(fgets())。
关于php - 解码gzip(使用PHP套接字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3469040/