我尝试在php上编写简单的解析器,只能给我HTML页面的内容长度。现在我有了这个代码:
$urls = array(
'http://Link1.com/',
'http://Link2.com'
);
$mh = curl_multi_init();
$connectionArray = array();
foreach($urls as $key => $url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($mh, $ch);
$connectionArray[$key] = $ch;
}
$running = null;
do
{
curl_multi_exec($mh, $running);
}while($running > 0);
foreach($connectionArray as $key => $ch)
{
$content = curl_multi_getcontent($ch);
echo $content."<br>";
curl_multi_remove_handle($mh, $ch);
}
curl_multi_close($mh);
如何从$ content获取Content-Length
?
答案 0 :(得分:1)
您可以使用curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD)
来返回:
下载内容的长度,请从“内容长度:”字段中读取
在这种情况下,-1
似乎是valid response:
从7.19.4开始,如果大小未知,则返回-1。