title: Laravel - Guzzle: Getting GuzzleHttp\Exception\ConnectException: cURL error 6 Could not resolve host randomly
body: <p>This is probably the weirdest situation that I ever seen. Basically I have a system built in Laravel 5.1 which needs to make a request to an external system. The thing is, sometimes it works but sometimes I get</p>
  
  <pre><code>GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: hosthere
  </code></pre>
  
  <p>Absolutely nothing changes, in terms of code. I run the application with exactly the same parameters and sometimes I get the error, sometimes I get the right response.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT 2</strong>
  When I execute nslookup domainthatineedtouse.com I get</p>
  
  <pre><code>;; Got SERVFAIL reply from 8.8.8.8, trying next server
  Server: 8.8.4.4
  Address:    8.8.4.4#53
  
  Non-authoritative answer:
  Name:   domainthatineedtouse.com
  Address: therealipaddressishere
  </code></pre>
  
  <p>Can this be related to the issue?</p>
  
  <p><strong>EDIT</strong>
  This is part of the class that is making the connection.</p>
  
  <pre><code>&lt;?php
  
  
  use GuzzleHttp\ClientInterface;
  
  class MyClass
  {
      const ENDPOINT = 'http://example.com/v1/endpoint';
  
      /**
       * @var \GuzzleHttp\ClientInterface
       */
      protected $client;
  
      /**
       * @var string The api key used to connect to the service
       */
      protected $apiKey;
  
      /**
       * Constructor.
       *
       * @param $apiKey
       * @param ClientInterface $client
       */
      public function __construct($apiKey, ClientInterface $client)
      {
          $this-&gt;client = $client;
          $this-&gt;apiKey = $apiKey;
      }
  
      /**
       * Here is where I make the request
       *
       * @param $param1
       * @param $param2
       * @return \Psr\Http\Message\ResponseInterface
       */
      public function makeTheRequest($param1, $param2)
      {
          return $this-&gt;client-&gt;request('get', self::ENDPOINT, [
              'query' =&gt; [
                  'api_token' =&gt; $this-&gt;apiKey,
                  'parameter_1' =&gt; $param1,
                  'parameter_2' =&gt; $param2,
              ]
          ]);
      }
  }
  </code></pre>