简体   繁体   中英

curl_multi_getcontent gives me less results

I want to store curl_multi_exec records to a variable but it didn't work out for me after using CURLOPT_RETURNTRANSFER = TRUE, then I did some research and add curl_multi_getcontent this works fine I mean its record values for the variable but the problem is it only stores few results in the variable.

$ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $stream_url,
        CURLOPT_ENCODING => "gzip",
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_USERPWD => $user.":".$pass,
        CURLOPT_WRITEFUNCTION => "print_out_data",
        //CURLOPT_RETURNTRANSFER => true,
        CURLOPT_VERBOSE => true // uncomment for curl verbosity

    ));

    $running = null;

    $mh = curl_multi_init();
    curl_multi_add_handle($mh, $ch);


    do {
        curl_multi_select($mh, 1);      
        curl_multi_exec($mh, $running); 
       $content = curl_multi_getcontent($ch);

          $arr = json_decode($content, true);
       // print_r($arr);
          $foo = $arr['id'];
          $bar = $arr['body'];

    } while($running > 0);

    curl_multi_remove_handle($mh, $ch);
    curl_multi_close($ch);

Before do{}while() write

$content = array();

Line

$content = curl_multi_getcontent($ch);

Replace to

$content[] = curl_multi_getcontent($ch);

After your loop write

print_r($content);

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