Answers.Body: <p>As Brad says, server side requests won't show up in your browser's dev tools. There's a few ways you can debug the calls:</p>
  
  <p>First, if you simply want to know if the Guzzle request ran and completed successfully, the easiest option is to use Craft's built-in logging feature by calling <code>MyPlugin::log</code> (obviously, replace "MyPlugin" with the real handle for your plugin):</p>
  
  <pre><code>MyPlugin::log('For those about to guzzle.');
  
  try {
      $response = $client-&gt;send($request);
      MyPlugin::log('I guzzled!');
  } catch (\Exception $e) {
      MyPlugin::log('Omg guzzling failed: '.$e-&gt;getMessage(), LogLevel::Error);
  }
  </code></pre>
  
  <p><code>MyPlugin::log</code> will write whatever you feed it to a file called <code>/craft/storage/runtime/logs/myplugin.log</code>. On a Unix-based system (such as OS X) you can monitor this file for changes by writing <code>$ tail -f myplugin.log</code> in your Terminal.</p>
  
  <p>Obviously, the <code>log</code> function will only accept string values. If you need to debug an object – e.g. the Guzzle response – you can simply JSON encode it:</p>
  
  <pre><code>MyPlugin::log('I guzzled, and all I got was '.json_encode($response));
  </code></pre>
  
  <p>For large/complex objects, this isn't really feasible, though – the log file will quickly become too large and/or unreadable. Beyond JSON, there's a few other options for object logging <a href="https://craftcms.stackexchange.com/questions/8427/output-array-to-pluginlog">here</a>.</p>
  
  <p>As an alternative (or in addition) to Craft's built-in logging, you may want to look into remote logging tools as well. There's several, though I'm personally a big fan of <a href="https://rollbar.com/" rel="nofollow noreferrer">Rollbar</a>. Rollbar is designed to catch exceptions, but it also has a logging feature similar to Craft's – the difference being that the message isn't output to a local file, but sent off to your Rollbar account (and, optionally, to wherever you want – your email, a private Slack channel, whatever). <a href="https://github.com/boboldehampsink/rollbar" rel="nofollow noreferrer">There's even a Craft plugin</a>.</p>
  
  <p>Beyond simple logging: For real object inspection, you may want to look into XDebug, a debugging extension for PHP. By configuring an IDE like <a href="https://www.jetbrains.com/help/phpstorm/10.0/configuring-xdebug.html" rel="nofollow noreferrer">PHPStorm</a> with XDebug, you'll be able to set breakpoints in your code, and debug/inspect variables at runtime.</p>
  
  <p>Another option is to use a tool like <a href="https://craig.is/writing/chrome-logger" rel="nofollow noreferrer">Chrome Logger</a>, which will let you log strings and objects to Chrome's console (basically just like you'd use <code>console.log</code> in JavaScript).</p>
  
  <p><strong>Edit</strong> 
  I just realized that you're not actually writing your own plugin, which makes the above answer less useful.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-07T10:36:07.810Z
Answers.Text: Mats that is totally useful. I've adapted the GEo plugin to extra guzzle and do some more data merging.  The data object is pretty small so i'll give  craft logging a go first before. I'm using PhpStorm so adding xdebug will be the next port of call when and if i start getting more complexity
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-07T17:41:19.547Z
Answers.Text: @joomkit Awesome!
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-06T09:54:46.047Z
Answers.LastActivityDate: 2016-07-07T17:42:55.233Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p><strong>Update:</strong></p>
  
  <p>Turns out server side initiated remote calls won't be logged in your browser's Network tab (only client-side ones).  Which now that I type that out, seems very obvious.</p>
  
  <hr>
  
  <p>If Guzzle actually makes a request, then it will show up in your browser's inspector's "Network" tab.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-05T08:17:40.683Z
Answers.Text: Well its definitely making requests as the plugin is getting data back and caching it. But i never see a request in the network tab. I wonder if you need to explicitly set something in guzzle because i don't see anything. I wanted to use it to check that requested data was cached properly and not requesting on every page. Its working as expected in this respect but I just don't see the first before-cache requests. ....
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-05T21:32:29.637Z
Answers.Text: Updated answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-06T22:16:41.200Z
Answers.Text: FWIW, I actually xDebugged this while testing and caching looks like it's working as you'd expect.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-04T03:39:55.893Z
Answers.LastActivityDate: 2016-07-05T21:32:24.087Z
Answers.LastEditDate: 2016-07-05T21:32:24.087Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've been adapting the very useful geo plugin to fetch currency and exchange rates based on a visitors IP address. [ see: <a href="https://github.com/lukeholder/craft-geo" rel="nofollow">https://github.com/lukeholder/craft-geo</a> ]</p>
  
  <p>The plugin uses Craft's vendor package "guzzle" to contact 3rd party APIs and request data which then gets cached in JSON form.</p>
  
  <p>When its not cached i was wondering how can you tell if Guzzle is making the request - there are no headers in dev tools and no noticeable traffic for the requests. So how can you see if the Guzzle has guzzled when cache is off?</p>
  
Tags: <cache><guzzle>
Title: Using guzzle with a plugin and cache
ThreadText: # Using guzzle with a plugin and cache
  
  (Asked by: username_0 on 2016-07-03)
  
  I've been adapting the very useful geo plugin to fetch currency and exchange rates based on a visitors IP address. [ see: <https://github.com/lukeholder/craft-geo> ]
  
  The plugin uses Craft's vendor package "guzzle" to contact 3rd party APIs and request data which then gets cached in JSON form.
  
  When its not cached i was wondering how can you tell if Guzzle is making the request - there are no headers in dev tools and no noticeable traffic for the requests. So how can you see if the Guzzle has guzzled when cache is off?
  
  **Tags:** cache, guzzle
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-07-06. Score: 1 | Accepted answer
  
  As username_2 says, server side requests won't show up in your browser's dev tools. There's a few ways you can debug the calls:
  
  First, if you simply want to know if the Guzzle request ran and completed successfully, the easiest option is to use Craft's built-in logging feature by calling `MyPlugin::log` (obviously, replace "MyPlugin" with the real handle for your plugin):
  
  ```
  MyPlugin::log('For those about to guzzle.');
  
  try {
      $response = $client->send($request);
      MyPlugin::log('I guzzled!');
  } catch (\Exception $e) {
      MyPlugin::log('Omg guzzling failed: '.$e->getMessage(), LogLevel::Error);
  }
  
  ```
  
  `MyPlugin::log` will write whatever you feed it to a file called `/craft/storage/runtime/logs/myplugin.log`. On a Unix-based system (such as OS X) you can monitor this file for changes by writing `$ tail -f myplugin.log` in your Terminal.
  
  Obviously, the `log` function will only accept string values. If you need to debug an object – e.g. the Guzzle response – you can simply JSON encode it:
  
  ```
  MyPlugin::log('I guzzled, and all I got was '.json_encode($response));
  
  ```
  
  For large/complex objects, this isn't really feasible, though – the log file will quickly become too large and/or unreadable. Beyond JSON, there's a few other options for object logging [here](https://craftcms.stackexchange.com/questions/8427/output-array-to-pluginlog).
  
  As an alternative (or in addition) to Craft's built-in logging, you may want to look into remote logging tools as well. There's several, though I'm personally a big fan of [Rollbar](https://rollbar.com/). Rollbar is designed to catch exceptions, but it also has a logging feature similar to Craft's – the difference being that the message isn't output to a local file, but sent off to your Rollbar account (and, optionally, to wherever you want – your email, a private Slack channel, whatever). [There's even a Craft plugin](https://github.com/boboldehampsink/rollbar).
  
  Beyond simple logging: For real object inspection, you may want to look into XDebug, a debugging extension for PHP. By configuring an IDE like [PHPStorm](https://www.jetbrains.com/help/phpstorm/10.0/configuring-xdebug.html) with XDebug, you'll be able to set breakpoints in your code, and debug/inspect variables at runtime.
  
  Another option is to use a tool like [Chrome Logger](https://craig.is/writing/chrome-logger), which will let you log strings and objects to Chrome's console (basically just like you'd use `console.log` in JavaScript).
  
  **Edit**
  I just realized that you're not actually writing your own plugin, which makes the above answer less useful.
  
  > **Comments:**
  > **username_0**: username_1 that is totally useful. I've adapted the GEo plugin to extra guzzle and do some more data merging.  The data object is pretty small so i'll give  craft logging a go first before. I'm using PhpStorm so adding xdebug will be the next port of call when and if i start getting more complexity  
  > **username_1**: @username_0 Awesome!  
  
  ---
  
  ### Answer by username_2 on 2016-07-04. Score: 2
  
  **Update:**
  
  Turns out server side initiated remote calls won't be logged in your browser's Network tab (only client-side ones). Which now that I type that out, seems very obvious.
  
  ---
  
  If Guzzle actually makes a request, then it will show up in your browser's inspector's "Network" tab.
  
  > **Comments:**
  > **username_0**: Well its definitely making requests as the plugin is getting data back and caching it. But i never see a request in the network tab. I wonder if you need to explicitly set something in guzzle because i don't see anything. I wanted to use it to check that requested data was cached properly and not requesting on every page. Its working as expected in this respect but I just don't see the first before-cache requests. ....  
  > **username_2**: Updated answer.  
  > **username_2**: FWIW, I actually xDebugged this while testing and caching looks like it's working as you'd expect.  
  
  ---
  
  