开发者

PHP cURL echoing curl_multi_exec

开发者 https://www.devze.com 2023-03-05 21:29 出处:网络
With normal curl when I went on page with normal curl it gave me the source code of one page. And I could just get it as string like this :

With normal curl when I went on page with normal curl it gave me the source code of one page. And I could just get it as string like this :

$ch = curl_init();
$contents = curl_exec($ch);
echo $contents;  // echos sourcecode of one page

But now i have curl_multi_exec, I tried echoi开发者_C百科ng it, but it gave me 0000000000000.

$mh = curl_multi_init();

curl_multi_add_handle($mh,$curls[0]);
curl_multi_add_handle($mh,$curls[1]);
curl_multi_add_handle($mh,$curls[2]);
curl_multi_add_handle($mh,$curls[3]);
curl_multi_add_handle($mh,$curls[4]);


$running = null;
do {
    usleep(10000);
    $sisu = curl_multi_exec($mh, $running);
} while($running > 0);
echo $sisu;  // just echos 000000000000000 , but it should echo source of 5 pages

What I am doing wrong?


Have a look at the curl_multi_getcontent() function and the CURLOPT_RETURNTRANSFER option.

There's a nice example of using the curl_multi code here: http://www.jaisenmathai.com/articles/php-curl-asynchronous.html


Try this after the while loop:

for($i=0;$i<5;$i++) {
    $resps[$i] = curl_multi_getcontent($curls[$i]);
    echo $resps[$i];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消