Answer the question
In order to leave comments, you need to log in
How to send multithreaded data via cURL?
I need to send more than one stream at the same time through cURL data to the server. I made one thread and it works fine, but I can no longer understand how to organize it.
I did it in one thread and it works.
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/rss+xml',
'Authorization: OAuth ' . TOKEN
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $putData);
curl_close($ch);
foreach ($files as $i => $data) {
$curl_arr[$i] = curl_init($url);
curl_setopt($curl_arr[$i], CURLOPT_HTTPHEADER, array(
'Content-Type: application/rss+xml',
'Authorization: OAuth ' . TOKEN
));
curl_setopt($curl_arr[$i], CURLOPT_POST, 1);
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_arr[$i], CURLOPT_POSTFIELDS, $putData);
curl_multi_add_handle($multi, $curl_arr[$i]);
}
$running = NULL;
do {
curl_multi_exec($multi, $running);
} while ($running > 0);
foreach ($files as $i => $data) {
curl_multi_remove_handle($multi, $curl_arr[$i]);
}
curl_multi_close($multi);
Answer the question
In order to leave comments, you need to log in
Guzzle is very handy - docs.guzzlephp.org/en/stable/quickstart.html You can send requests asynchronously, you can wait until the entire request pool is completed and call the method when they complete, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question