0

I make requests to Api, there is a limit on api for no more than 5 parallel requests , this CURLMOPT_MAX_CONNECTION doesn't seem to work, what am I doing wrong. I could use simple curl, but it throws a 500 error. I will be glad for any help.

foreach ($productReport2['rows'] as $productReports) {
/*var_export($productReports['meta']['href']);*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $productReports['meta']['href']);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$login");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLMOPT_MAX_CONNECTION, 4);
curl_multi_add_handle($multi, $ch);
$channels[$productReports['meta']['href']] = $ch; }
$active = null;
do {
$mrc = curl_multi_exec($multi, $active);


} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($multi) == -1) {  // -1 def
        usleep(1);  // continue def
    }
    do {
        $mrc = curl_multi_exec($multi, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
}

foreach ($channels as $channel) {

    $productHref = curl_multi_getcontent($channel);
    fwrite($handler, $productHref);
    /*file_put_contents($filename, $productHref);*/
    unset($productHref);

    /*print_r($productReports['stock']." : " .$id['id']. " ");*/

    curl_multi_remove_handle($multi, $channel);
}
        curl_multi_close($multi);
john Wick
  • 1
  • 1
  • 1
    Maybe you are looking for parameter `CURLMOPT_MAX_TOTAL_CONNECTIONS`? Some readings explaining this option: https://curl.se/libcurl/c/CURLMOPT_MAX_TOTAL_CONNECTIONS.html. Please also check the documentation (https://www.php.net/manual/en/function.curl-setopt.php) how to set options and be aware of the version of used libcurl. – TomiL Oct 06 '21 at 06:45
  • 1
    I found solution, thank you for the answer. – john Wick Oct 07 '21 at 11:25
  • did my comment help you? It's a good practice to describe found solution step(s) in case you figured it out on your own or UPVOTE user('s) suggestion, so that the one with same problem you had could easily overcome this issue when she/he lands on this page...that's the whole idea of this portal :) Thank you and keep up the good work! – TomiL Oct 11 '21 at 08:33

0 Answers0