title: Is it necessary to close a cURL connection?
body: <p>I created a wrapper function for cURL in PHP. Its simplified version looks like this:</p>
  
  <pre><code>function curl_get_contents($url, $try = 1) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, '1');
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '1'); 
  
      // Execute the curl session
      $output = curl_exec($ch);
  
      if ($output === FALSE) {
          if ($try == 1) { //Try again
              return $this-&gt;curl_get_contents($url, 2);
          } else {
              return false;
          }    
      }        
  }
  </code></pre>
  
  <p>As you can see, I force a retry of the function if it fails. Do I need to run <code>curl_close()</code>? Does PHP close all handles at the end of the script?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The linked question is extremely vague in its answer and doesn't support itself with data. I would really appreciate an answer based on perhaps a profiler that shows that PHP closes the connection immediately.</p>