title: How can I capture the IP used by cURL in Guzzle?
body: <p>I'm using Goutte (which internally uses Guzzle) for a web scraping project. I'm working on a custom rate limiter, and so am storing all HTTP operations to a database table against an IP so I can check if a call has been made to a host in a recent timeframe.</p>
  
  <p>Currently I'm using <code>gethostbyname</code> to convert the known hostname to an IP address, but Guzzle would already have done a lookup, and so this may be wasteful. Moreover, hostnames may resolve to more than one IP address (hence the need for <code>gethostbynamel</code>) so the IP I derive myself may not in fact be the one that Guzzle has used (though, at a guess, there could be some caching at the PHP level that would make it likely <code>gethostbyname</code> returns the correct result).</p>
  
  <p>I've subscribed a plugin to Guzzle, which returns some very interesting data from cURL, in an effort to do this. Sadly, the IP address was not among them. There <em>must</em> be a way to get this though - any ideas?</p>
  
  <pre><code>class HttpLoggerPlugin implements EventSubscriberInterface
  {
      public static function getSubscribedEvents()
      {
          return array(
              'request.complete' =&gt; 'onRequestComplete',
          );
      }
  
      /**
       * Handles the request complete event (for both success/failed)
       * 
       * @param \Guzzle\Common\Event $event
       */
      public function onRequestComplete(Event $event)
      {
          $request = $event['request'];
          $host = $request-&gt;getHost();
  
          $ip = gethostbyname($host);
          $response = $event['response'];
          $responseCode = $response ? $response-&gt;getStatusCode() : null;
          // Try to get cURL data here
          echo $response ? print_r($response-&gt;getInfo(), true) : null;
      }
  }
  </code></pre>
  
  <p>This is what the <code>$response-&gt;getInfo()</code> returns:</p>
  
  <pre><code> Array(
          [url] =&gt; http://example.com/page.html
          [content_type] =&gt; text/html
          [http_code] =&gt; 200
          [header_size] =&gt; 228
          [request_size] =&gt; 149
          [filetime] =&gt; -1
          [ssl_verify_result] =&gt; 0
          [redirect_count] =&gt; 0
          [total_time] =&gt; 1.209516
          [namelookup_time] =&gt; 0.559758
          [connect_time] =&gt; 0.954811
          [pretransfer_time] =&gt; 0.954916
          [size_upload] =&gt; 0
          [size_download] =&gt; 22390
          [speed_download] =&gt; 18511
          [speed_upload] =&gt; 0
          [download_content_length] =&gt; 22390
          [upload_content_length] =&gt; 0
          [starttransfer_time] =&gt; 1.056913
          [redirect_time] =&gt; 0
          [certinfo] =&gt; Array()
          [redirect_url] =&gt; 
   )
  </code></pre>