Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取响应的“内容长度”_Php_Curl - Fatal编程技术网

Php 如何获取响应的“内容长度”

Php 如何获取响应的“内容长度”,php,curl,Php,Curl,我试着在php上写一个简单的解析器,可以给我html页面的内容长度。目前,我有以下代码: $urls = array( 'http://Link1.com/', 'http://Link2.com' ); $mh = curl_multi_init(); $connectionArray = array(); foreach($urls as $key => $url) { $ch = curl_ini

我试着在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);
$url=array(
'http://Link1.com/',
'http://Link2.com'
);
$mh=curl_multi_init();
$connectionArray=array();
foreach($url作为$key=>$url)
{
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_头,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
卷曲多加手柄($mh,$ch);
$connectionArray[$key]=$ch;
}
$running=null;
做
{
curl_multi_exec($mh,$running);
}而($running>0);
foreach($connectionArray作为$key=>$ch)
{
$content=curl\u multi\u getcontent($ch);
echo$content.“
”; 卷曲多个拆卸手柄($mh,$ch); } 卷曲多重闭合($mh);
如何从$Content中获取
内容长度

您可以使用返回:

下载的内容长度,从内容长度:字段读取

在这种特殊情况下,
-1
似乎是:

从7.19.4开始,如果大小未知,则返回-1


我试着使用这个
$info=curl\u getinfo($content,CURLINFO\u content\u LENGTH\u DOWNLOAD)没有工作。我只得到了


,没有任何结果。你应该使用
$info=curl\u getinfo($ch,CURLINFO\u CONTENT\u LENGTH\u DOWNLOAD)很奇怪,但现在我得到了
-1
-1
@Сëëëë请您也检查一下
$info=curl\u getinfo($mh,CURLINFO\u CONTENT\u LENGTH\u DOWNLOAD)