Reputation: 888
I try to write simple parser on php, with can give me only content-length of html page. For now I have this Code :
$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);
How can I get Content-Length
from $content ?
Upvotes: 0
Views: 4567
Reputation: 14365
You can use curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD)
which returns:
Content length of download, read from Content-Length: field
In this particular case, -1
seems to be a valid response:
Since 7.19.4, this returns -1 if the size isn't known.
Upvotes: 1