php single curl works but multi curl doesn't work? php single curl works but multi curl doesn't work? curl curl

php single curl works but multi curl doesn't work?


I just answered another question that I found about multiple curl calls.

This is all I did to run the requests.

do {    $status = curl_multi_exec($mh, $running);} while ($status === CURLM_CALL_MULTI_PERFORM || $running);

Then I fetched the info I needed by looping over my array of curl handlers.

$returned = array();foreach ($requests as $identifier => $request) {    $returned[$identifier] = curl_multi_getcontent($request);    curl_multi_remove_handle($mh, $request);    curl_close($request);}

The above approach worked for me, however it seems like you want to add only a certain amount of sessions to the curl multi-handler. We could probably change the do-while loop above to the following:

do {    $status = curl_multi_exec($mh, $running);    if ($running < $window) {        for ($x = 0; $x < $window - $running; $x++) {            $index = count($site_map) + $x -1;            curl_multi_add_handle($mh, $this->sessions[$index]);            $site_map[(string) $this->sessions[$index]] = $index;        }    }} while ($status === CURLM_CALL_MULTI_PERFORM || $running);

After that we could modify the data fetch and replace your whole while ($running && $execrun === CURLM_OK){} section with the following since it will only run once all your curl calls have been processed:

$returned = array();foreach ($this->sessions as $identifier => $request) {    $returned[$identifier] = curl_multi_getcontent($request);    curl_multi_remove_handle($mh, $request);    curl_close($request);}


I had tried running both singe curl_exec() and curl_multi_exec() on the same page and got no response as well, until I did:unset($ch);, after the single request.