简体   繁体   中英

PHP cURL echoing curl_multi_exec

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 echoing 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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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