1

I am trying to do curl_muliti_*, but I am having issues, and I don't know what is causing the problem. When I run the following code, I get stuck in an infinite loop here while($active && $mrc === CURLM_OK){

$active = null;
do{
    $mrc = curl_multi_exec($mh, $active);
}while($mrc === CURLM_CALL_MULTI_PERFORM);

while($active && $mrc === CURLM_OK){
    if(curl_multi_select($mh) !== -1){
        do{
            $mrc = curl_multi_exec($mh, $active);
        }while($mrc === CURLM_CALL_MULTI_PERFORM);
    }
}

in the loop (above the if) I add var_dump(curl_multi_select($mh)) and it outputs int(-1) Why is it doing that?

Here is the full method:

protected function getURLs($other_params = array()){
    $url      = $this->url;
    $url_list = array();
    if(!is_array($url)){
        return false;
    }
    $mh = curl_multi_init();
    foreach($url as $u){
        $url_list[] = $handle = $this->curlInit($u, $other_params);
        curl_multi_add_handle($mh, $handle);
    }
    $active = null;
    do{
        $mrc = curl_multi_exec($mh, $active);
    }while($mrc === CURLM_CALL_MULTI_PERFORM);

    while($active && $mrc === CURLM_OK){
        if(curl_multi_select($mh) !== -1){
            do{
                $mrc = curl_multi_exec($mh, $active);
            }while($mrc === CURLM_CALL_MULTI_PERFORM);
        }
    }
    $data = array();
    foreach($url_list as $handle){
        $data[] = curl_multi_getcontent($handle);
        curl_multi_remove_handle($mh, $handle);
    }
    curl_multi_close($mh);

    return $data;
}

Note: Let me know what other code you may need.

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
  • Perhaps it's because `$active` will return false and not true.. So how about: `while (!$active && $mrc){` or set `$active` to represent true by giving it a value: `$active = true;` then: `while ($active && $mrc)` – Daryl Gill Jul 31 '13 at 01:57
  • I pulled that loop directly from php.net http://us2.php.net/curl_multi_init – Get Off My Lawn Jul 31 '13 at 02:01
  • that was an assumption based on first looks, hence why I didn't post it as a possible answer. I will look into it and get back to you – Daryl Gill Jul 31 '13 at 02:03
  • 1
    @DarylGill I was able to get it by placing `$mrc = curl_multi_exec($mh, $active);` right above the `if()` – Get Off My Lawn Jul 31 '13 at 02:48

0 Answers0