doubleD
doubleD

Reputation: 536

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);

Upvotes: 0

Views: 451

Answers (1)

Winston
Winston

Reputation: 1805

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);

Upvotes: 2

Related Questions