F
F
Formula_12018-04-27 08:52:14
PHP
Formula_1, 2018-04-27 08:52:14

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

1 answer(s)
A
Arman, 2018-04-27
@Arik

php.net/manual/en/function.curl-multi-init.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question