使用curl从PHP下载gzip压缩的XML文件时,我遇到了一个非常奇怪的行为(bug?)。错误消息显示为:
处理内容取消编码时出错:设置的代码长度无效
奇怪的是,它只在使用PHP的curl 时在我的本地机器上发生。在我的服务器上运行完全相同的脚本将成功,并在我的本地计算机上运行curl.exe独立(有关所用系统的更多详细信息,请参阅下文)。
这让我相信它可能是php_curl.dll(curl版本7.36.0)中的一个错误。
具有类似设置的人可以确认此问题吗?
本地PHP设置(错误):
远程PHP设置(有效)
本地独立卷曲(有效):
来自PHP
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.tchibo.de/sitemap-pv-pa.xml");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
if(curl_exec($curl) === false) {
echo 'Error: ' . curl_error($curl);
}
else {
echo 'Success!';
}
curl_close ($curl);
将输出类似的内容(失败时):
* Hostname was NOT found in DNS cache
* Trying 212.116.1.40...
* Connected to www.tchibo.de (212.116.1.40) port 80 (#0)
> GET /sitemap-pv-pa.xml HTTP/1.1
Host: www.tchibo.de
Accept: */*
Accept-Encoding: gzip
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Content-Disposition: attachment; filename="sitemap-pv-pa.xml"
< Content-Type: text/xml;charset=UTF-8
< Transfer-Encoding: chunked
< Content-Encoding: gzip
< Vary: Accept-Encoding
< Date: Thu, 02 Oct 2014 09:10:58 GMT
<
* Error while processing content unencoding: invalid code lengths set
* Failed writing data
* Closing connection 0
Error: Error while processing content unencoding: invalid code lengths set
从命令行
[curl.exe的路径] --compress -v“http://www.tchibo.de/sitemap-pv-pa.xml”&gt; tmp.txt
输出(成功)
C:\curl-versions\7.36\bin>curl.exe --compress -v "http://www.tchibo.de/sitemap-pv-pa.xml" > tmp.txt
* Hostname was NOT found in DNS cache
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 212.116.1.40...
* Connected to www.tchibo.de (212.116.1.40) port 80 (#0)
> GET /sitemap-pv-pa.xml HTTP/1.1
> User-Agent: curl/7.36.0
> Host: www.tchibo.de
> Accept: */*
> Accept-Encoding: deflate, gzip
>
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Content-Disposition: attachment; filename="sitemap-pv-pa.xml"
< Content-Type: text/xml;charset=UTF-8
< Transfer-Encoding: chunked
< Content-Encoding: gzip
< Vary: Accept-Encoding
< Date: Thu, 02 Oct 2014 09:34:18 GMT
<
{ [data not shown]
100 814k 0 814k 0 0 791k 0 --:--:-- 0:00:01 --:--:-- 803k
* Connection #0 to host www.tchibo.de left intact