title: Using cURL in a loop
body: <p>I'm writing a script in which an unspecified number of files need to be uploaded via cURL requests to a remote API. However, this script hangs and eventually times out. Strangely enough, all the requests are successful (the files are successfully uploaded), but the script is unable to continue. Here's the loop:</p>
  
  <pre><code>foreach ($paths as $path) {
    $ch = curl_init($path);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Token: '.$token, 'Content-Length: '.filesize($path));
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_setopt($ch, CURLOPT_INFILE, fopen($path, 'r'));
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize($path));
    echo curl_exec($ch);
  }
  </code></pre>
  
  <p>I believe this has something to do with the loop. I've tried adding <code>curl_close</code> within the loop, but it doesn't solve the problem. Any ideas?</p>