title: Limit connecting time with Guzzle HTTP PHP client
body: <p>I'm using Guzzle to open a list of url-s and get the headers. Some of the urls are taking too long to respond and can't be openned and i want to ignore them. It takes me up to 20+ seconds before Guzzle throws an exception and i want to change this and limit the time for connecting to 2 sec. I have this code but it still takes much longer:</p>
  
  <pre><code>&lt;?php
  include 'vendor/autoload.php';
  
  $start = new \DateTime("now");
  
  $start = $start-&gt;format("d.m.Y H:i:s");
  echo $start."\n";
  $client = new Guzzle\Http\Client();
  
  Guzzle\Http\StaticClient::mount();
  
  try {
      $request = $client-&gt;get('http://takestoolongexample', [], ['connect_timeout' =&gt; 2, 'timeout' =&gt; 3, 'debug' =&gt; true]);
      $response = $request-&gt;send();
  
      var_dump($response-&gt;getStatusCode());
  } catch (Exception $e) {
      echo "\n".$e-&gt;getMessage()."\n";
  }
  
  $end = new \DateTime("now");
  
  $end = $end-&gt;format("d.m.Y H:i:s");
  
  echo "\n".$end."\n";
  ?&gt;
  </code></pre>
  
  <p>Here's an example result. As you can see, it took 13 seconds.</p>
  
  <pre><code>$ php test.php
  30.12.2013 22:00:07
  * getaddrinfo(3) failed for takestoolongexample:80
  * Couldn't resolve host 'takestoolongexample'
  * Closing connection 0
  
  [curl] 6: Couldn't resolve host 'http://takestoolongexample' http://takestoolongexample
  
  30.12.2013 22:00:20
  </code></pre>
  
  <p>(<code>http://takestoolongexample</code> was a real url, changed it here)</p>