【发布时间】:2010-05-26 16:08:33
【问题描述】:
我尝试了一些方法来使用 PHP Simple HTML DOM Parser 启用 gzip 压缩,但到目前为止似乎没有任何效果。使用 ini_set 我已经设法更改用户代理,所以我认为也可以启用 gzip 压缩?
include("simpdom/simple_html_dom.php");
ini_set('zlib.output_compression', 'On');
$url = 'http://www.whatsmyip.org/http_compression/';
$html = file_get_html($url);
print $html;
上面的网站对其进行了测试。如果我完全错误地处理这个问题,请告诉我。
====
更新
对于其他试图实现相同目标的人,最好只使用 cURL,然后像这样使用 dom 解析器:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // Define target site
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string
curl_setopt($cr, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2');
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_TIMEOUT,5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
$return = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$html = str_get_html("$return");
【问题讨论】: