Hi,
I am using fsockopen to retrieve an HTML page that has been compressed, but when I try and decompress the string I get the following error :
Warning: gzuncompress() [function.gzuncompress]: data error
I found a bug report on the PHP pages at sourceforge that said it was something to do with the gzip header and the workaround was to write the string to a temp file then read it in using the gzip file routines. I don't want to do this because there will be a lot of requests, anybody got any ideas?
I have attached the code here but it won't work on your systems because of the url.
$request.="POST ".$HBD['urlinfo']['path']." HTTP/1.1\n";
$request.="Host: ".$HBD['urlinfo']['host']."\n";
$request.="Referer: ".$HBD['referer']."\n";
$request.="Content-type: application/x- $request.="Content-length: ".strlen($HBD['RQ'])."\n";
if($HBD['decompress']){
$request.="Accept-Encoding: gzip, deflate\n";
}
$request.="Connection: close\n";
$request.="\n";
$request.=$HBD['RQ']."\n";
$fp = fsockopen($HBD['urlinfo']['host'],80);
fputs($fp, $request);
$HBDResult='';
while(!feof($fp)) {
$HBDResult .= fgets($fp, 128);
}
fclose($fp);
$HBDResult = substr($HBDResult,strpos($HBDResult,"\r\n\r\n"));
if($HBD['decompress']){
$HBDResult = gzuncompress($HBDResult);
}
Thanks
Hope this helps,
Phil Clare
I am using fsockopen to retrieve an HTML page that has been compressed, but when I try and decompress the string I get the following error :
Warning: gzuncompress() [function.gzuncompress]: data error
I found a bug report on the PHP pages at sourceforge that said it was something to do with the gzip header and the workaround was to write the string to a temp file then read it in using the gzip file routines. I don't want to do this because there will be a lot of requests, anybody got any ideas?
I have attached the code here but it won't work on your systems because of the url.
$request.="POST ".$HBD['urlinfo']['path']." HTTP/1.1\n";
$request.="Host: ".$HBD['urlinfo']['host']."\n";
$request.="Referer: ".$HBD['referer']."\n";
$request.="Content-type: application/x- $request.="Content-length: ".strlen($HBD['RQ'])."\n";
if($HBD['decompress']){
$request.="Accept-Encoding: gzip, deflate\n";
}
$request.="Connection: close\n";
$request.="\n";
$request.=$HBD['RQ']."\n";
$fp = fsockopen($HBD['urlinfo']['host'],80);
fputs($fp, $request);
$HBDResult='';
while(!feof($fp)) {
$HBDResult .= fgets($fp, 128);
}
fclose($fp);
$HBDResult = substr($HBDResult,strpos($HBDResult,"\r\n\r\n"));
if($HBD['decompress']){
$HBDResult = gzuncompress($HBDResult);
}
Thanks
Hope this helps,
Phil Clare