Answer the question
In order to leave comments, you need to log in
Deal with multiCurl?
Good evening, I’m sorry right away, I couldn’t describe the essence of the issue in the title of the normal. The problem in general is that, there is an API on the endpoint, the id of the product is transmitted, in response it will receive a description, prices, etc., but since there are a lot of products, I decided to try mCurl, but then I ran into such a problem. The code itself
$perRequest = 200;
for ($i = 0; $i < count($products); $i += $perRequest) {
$currentNodes = array_slice($products, $i, $perRequest);
$mh = curl_multi_init();
foreach ($currentNodes as $key => $value) {
$multiCurl[$key] = curl_init();
curl_setopt_array($multiCurl[$key], array(
CURLOPT_URL => 'https://site.com/' . $value['sku'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $token,
),
));
curl_multi_add_handle($mh, $multiCurl[$key]);
}
$index = null;
do {
curl_multi_exec($mh,$index);
} while ($index > 0);
foreach ($multiCurl as $k => $ch) {
$data[$k][$i] = json_decode(curl_multi_getcontent($ch), TRUE);
curl_multi_remove_handle($mh, $ch);
}
}
$value['sku']
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question