Answer the question
In order to leave comments, you need to log in
How to get request context in asynchronous curl request?
There are about 2 thousand urls where you need to go and collect data, synchronously it takes about 27 minutes.
I want to rewrite it to an asynchronous method in order to reduce the time it takes to receive data, but I don’t quite understand how, where, in fact, I can receive data. Moreover, I need to make sure that the newly received data clearly corresponds to a certain key in the array. So far, the implementation is very vague.
Please push in the right direction.
for($counter = 0; $counter < count($app_objects); $counter++){
$link = 'example.com';
$process = curl_init($link);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/json', false));
curl_setopt($process, CURLOPT_RETURNTRANSFER , 1);
$resources[$counter] = $process;
}
$multi_curl = curl_multi_init();
foreach ($resources as $resource){
curl_multi_add_handle($multi_curl,$resource);
}
$active = false;
do {
$mrc = curl_multi_exec($multi_curl, $active);
} while ($active > 0);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($multi_curl) != -1) {
do {
$mrc = curl_multi_exec($multi_curl, $active);
var_dump($mrc);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
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