简体   繁体   English

使用http和https进行多卷曲

[英]multi curl with http and https

I'm trying to use multi curl, but I'm not sure if the problem I'm having is because one link is regular http, and another link is https. 我正在尝试使用多卷曲,但是我不确定是否遇到问题是因为一个链接是常规http,而另一个链接是https。

I used curlsetopt($ch[$i],CURLOPT_SSL_VERIFYPEER,false) 我用了curlsetopt($ch[$i],CURLOPT_SSL_VERIFYPEER,false)

But I get an error message, if I make this to true, I don't get any errors, but I'm not getting any data from the https link. 但是我收到一条错误消息,如果我将其设置为真,则不会收到任何错误,但是不会从https链接获取任何数据。 would this be the problem? 这会是问题吗?

Error : Object of class stdClass could not be converted to string 错误: Object of class stdClass could not be converted to string

Thanks 谢谢

$urls = array(
  "http",
  "https"
   );

$mh = curl_multi_init();

foreach ($urls as $i => $url) {
       $conn[$i]=curl_init($url);
       curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string 
       curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects
       curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects
       curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout
       curl_setopt($conn[$i],CURLOPT_SSL_VERIFYPEER,false);
       curl_setopt($conn[$i],CURLOPT_HEADER,0);

       curl_multi_add_handle ($mh,$conn[$i]);
}

do { $n=curl_multi_exec($mh,$active); } while ($active);

foreach ($urls as $i => $url) {
       $res[$i]=curl_multi_getcontent($conn[$i]);
       curl_multi_remove_handle($mh,$conn[$i]);
       curl_close($conn[$i]);
}
curl_multi_close($mh);


print_r($res);

From playing more with this code. 从更多地使用此代码。 It does seem to work, 它似乎确实有效,

What does not work is print_r($res[0]); 不起作用的是print_r($res[0]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM