How between cURL requests to pause?

There is a function, which runs in a loop:
curlNew function($ur)
 //sleep(rand(2,4)); // first option (probably the most correct)
 $ch = curl_init($url); // initialize
 $link = $url;
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connecTimeout); // connection timeout
 curl_setopt($ch, CURLOPT_TIMEOUT, $maxTimeout); // max. execution
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
 curl_setopt($ch, THIS, false); 
 curl_setopt($ch, CURLOPT_REFERER, $url);
 curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
 curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
 if ($proxy) {curl_setopt($ch, CURLOPT_PROXY, $proxy);}
 //sleep(rand(2,4)); // second option
 $html = curl_exec($ch); // get the HTML
 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 $httpTime = round(curl_getinfo($ch, CURLINFO_TOTAL_TIME), 2);
 $proxyParse = parse_url("http://".$proxy, PHP_URL_HOST);

// ...

for ($i=0; $i < 3; $i++) { 
 echo curlNew();

Where better to insert a sleep () between requests was a pause. As I understand, if to determine the correct place in the code for sleep(), it will also affect the savings of server resources.
March 20th 20 at 11:50
3 answers
March 20th 20 at 11:52
Economii of server resources you will not succeed, because the longer the script the longer it will be occupied server resources. Here the resources of the data channel - Yes, I will be busy...

sleep() is better to do in the loop(), something "on the spot" it was possible to vary the speed of loading of data required.
March 20th 20 at 11:54
Immediately after the function call.

for ($i=0; $i < 3; $i++) { 
 echo curlNew();
March 20th 20 at 11:56
Generally, the right to do so.
First, do f-tion curl_init() before the loop, then the loop because curl_close().
Why do you have to open a bunch of sessions Kurla, if you can make one and send N queries?

$ch = curl_init();
foreach ($urls as $url) {
 echo curlNew($ch, $url);

And you do not need any slips. In General, the fire to do asynchronously, there are plenty of lib.

Find more questions by tags PHP