set_time_limit(0);
$ch = curl_init('http://www.tibia.com/community/?subtopic=highscores&world=Antica');
curl_setopt($ch, CURLOPT_RANGE, '0-999');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
echo $data = curl_exec($ch);//get curl response
curl_close($ch);
And the example output is (it is slightly different every time I hit refresh button):
‹í]kSã8ºþNÕüOÍÕr™&™‚ ³ÜÒ3{æ¥8J¢Æ±2¾é=ûßÏ«‹Û±BãYÜåž,[¥÷òHz%[ÎÁØ›XÖÆàˆÐG=‹tz´O1ª S‡té[ZxF tm[Ô&è–YÝÀ%jÐ'¿½?¿<ütrÇË‹_X_BD1‡Ýîõç«^¤œàŠ(Èå%ÓwH¤$lšÌ·½°¨Ñý)s&W¼‰Ç¯Rb ¢‰Ð{dЪ zp×½=¿é¡ÞÿÞœ,úµ³vð·JU«0D@EÔ²ˆ³æ¯G'„A{Û0Ì1tjä´ÜØ4þŽšµZmóãÚзMÞÆQ4{íßà=:DSì@³ß ò2Ý-‹Ø#oŒ:¨± ‰þ-üË1}‡=¹Äéͦ¨ÝF%F‹ºßb²#i˜éO¢W> à]û\b ·<6]~ßÿÿ?k v¥&¨JuÖÖÞ®PB)¶èWm ƒÁþ~}¿ÖÜÛö÷wš ÒØ®Õ04IØÜ!õdS€1½ªuHö
The page is displayed correctly when I comment out CURLOPT_RANGE
EDIT: I added curl_setopt($ch, CURLOPT_ENCODING, "gzip"); The output seems to be okay, but only when the range starts with 0. If the range is for example 2000-3000, it outputs completely nothing.
EDIT 2: The error message is: "Error while processing content unencoding: invalid distance too far back"
I've never used CURLOPT_RANGE. Is there a reason you need to use this?
The reason gzip only works when you start from 0 is there is information there that it needs to unzip the content. If you must use Range then you should capture the data for each range and combine it and then un-gzip that.
EDIT:
You mention in some comments that you use Range to get some of the data to save bandwidth. I checked the page using Firebug and it's < 10kb. With all the images it's almost 500k. You are already saving quite a bit and unless you're using dial-up internet 10kb it's nothing. Don't worry about using Range and combining the chunks, just let cURL handle the gzip.
You're getting gzipped content. You should explicitly state that you want plain HTML returned. You can add the following option:
curl_setopt($ch, CURLOPT_ENCODING, 'deflate');