title: Too many sockets open by cURL multi
body: <p>I am using cURL multi to get data from some websites. With code:</p>
  
  <pre><code>function getURL($ids)
  {
      global $mh;
      $curl = array();
      $response = array();
      $n = count($ids);
      for($i = 0; $i &lt; $n; $i++) {
          $id = $ids[$i];
          $url = 'http://www.domain.com/?id='.$id;
  
          // Init cURL
          $curl[$i] = curl_init($url);
          curl_setopt($curl[$i], CURLOPT_RETURNTRANSFER, true);
          curl_setopt($curl[$i], CURLOPT_CONNECTTIMEOUT, 30);
          curl_setopt($curl[$i], CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)');
          //curl_setopt($curl[$i], CURLOPT_FORBID_REUSE, true);
          //curl_setopt($curl[$i], CURLOPT_HEADER, false);
          curl_setopt($curl[$i], CURLOPT_HTTPHEADER, array(
              'Connection: Keep-Alive',
              'Keep-Alive: 300'
          ));
  
          // Set to multi cURL
          curl_multi_add_handle($mh, $curl[$i]);
      }
  
      // Execute 
      do {
          curl_multi_exec($mh, $flag);
      } while ($flag &gt; 0);
  
      // Get response
      for($i = 1; $i &lt; $n; $i++) {
          // Get data
          $id = $ids[$i];
          $response[] = array(
              'id' =&gt; $id,
              'data' =&gt; curl_multi_getcontent($curl[$i])
          );
  
          // Remove handle
          //curl_multi_remove_handle($mh, $curl[$i]);
      }
  
      // Reponse
      return $response;
  }
  </code></pre>
  
  <p>But, i have problem is cURL open too many sockets to connect to webserver. Each connection, cURL create new socket to webserver.
  I want to current connection is keep-alive for next connection. I don't want that 100 URL then cURL must create 100 sockets to handle :(</p>
  
  <p>Please help me. Thanks so much !</p>