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