Answer the question
In order to leave comments, you need to log in
Sending curl requests in a loop?
Good afternoon. When working with curl, a question arose: how to correctly send requests in a cycle, namely: should I open and close the session at each iteration, or should this be done outside the loop?
// открываем из вне
$curl = curl_init();
foreach ($paramArray as $param) {
// или при итерации
$curl = curl_init();
$url = "http://domain.com/script.php?param=" . $param;
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
));
$response = curl_exec($curl);
// также и по закрытию
curl_close($curl);
}
// также и по закрытию
curl_close($curl);
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