Answers.Body: <p>EDIT: <strong>See Eileen's updated answer above, this is now outdated.</strong></p>
  <p>As of 2021 CiviCRM bundles Guzzle!</p>
  <hr />
  <p>I'm unsure what's <em>recommended</em>, but there are several patterns (at least) through the codebase:</p>
  <ul>
  <li><a href="https://github.com/civicrm/civicrm-core/blob/d799e82070e2319bb5b2e580fabf90f64f907010/CRM/Utils/HttpClient.php" rel="nofollow noreferrer"><code>CRM_Utils_HttpClient</code></a>, used in core functionality like system checks. This has test coverage!</li>
  <li>PHP <a href="http://php.net/manual/en/book.curl.php" rel="nofollow noreferrer"><code>curl</code></a>, common in the payment processors.</li>
  <li>PEAR HTTP_Request, in older code like <a href="https://github.com/civicrm/civicrm-core/blob/294ea01475fbdce67534f6759307c80e19fad497/CRM/Utils/Geocode/Yahoo.php" rel="nofollow noreferrer">geocoders</a>.</li>
  <li>Occasionally <a href="https://github.com/civicrm/civicrm-core/blob/648631cd94799e87fe2347487d465b1a7256aa57/CRM/Utils/Check/Component/Security.php#L335" rel="nofollow noreferrer"><code>file_get_contents()</code></a> to switch things up for fun?</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-12T07:20:26.517Z
Answers.Text: I downvoted this because it was the right answer at the time but 2021 !== 2018
Answers.UserDisplayName: eileen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-06-01T22:39:51.687Z
Answers.LastActivityDate: 2021-08-13T20:26:35.997Z
Answers.LastEditDate: 2021-08-13T20:26:35.997Z
Answers.UserDisplayName: Chris Burgess
Answers.Body: <p>CiviCRM core has bundled in Guzzle for a few years now (this was an old issue that got highlighted just now) - so Guzzle is the recommended approach</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-12T07:19:49.057Z
Answers.LastActivityDate: 2021-08-12T07:19:49.057Z
Answers.UserDisplayName: eileen
Body: <p>I've written quite a few extensions that need a way to fetch data from the web. Sometimes I've used <code>file_get_contents</code> sometimes cURL, other times I've sucked in (geddit!) <a href="https://github.com/guzzle/guzzle" rel="noreferrer">Guzzle</a>. Each of those has it's own requirements.</p>
  
  <p>Just want to check that CiviCRM does not offer a service/wrapper for this that knows what is available? What's recommended?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-12T07:09:21.023Z
Comments.Text: great question. I am wondering in there is a more definitive answer in 2021: https://chat.civicrm.org/civicrm/pl/xgehp38t7ig88gg5soob3wua1y
Comments.UserDisplayName: michaelmcandrew
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-13T20:29:29.227Z
Comments.Text: are there dev docs or a module that uses CiviCRM's Guzzle which would be useful to an extension author as a reference? the example I found when I looked said `// currently not working` so I won't link to it here!
Comments.UserDisplayName: Chris Burgess
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-26T13:19:36.287Z
Comments.Text: @ChrisBurgess I don't think Civi needs a copy of [Guzzle's docs](https://docs.guzzlephp.org/en/6.5/)?
Comments.UserDisplayName: artfulrobot
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-28T21:40:07.110Z
Comments.Text: true :) [example](https://github.com/civicrm/civicrm-core/blob/5db0bc3c1f54eaca4307f103a73bda596ae914d6/CRM/Utils/Check/Component.php#L134-L145)
Comments.UserDisplayName: Chris Burgess
Tags: <developer>
Title: Fetch data over the web: curl, file_get_contents or something else?
ThreadText: # Fetch data over the web: curl, file_get_contents or something else?
  
  (Asked by: username_0 on 2017-06-01)
  
  I've written quite a few extensions that need a way to fetch data from the web. Sometimes I've used `file_get_contents` sometimes cURL, other times I've sucked in (geddit!) [Guzzle](https://github.com/guzzle/guzzle). Each of those has it's own requirements.
  
  Just want to check that CiviCRM does not offer a service/wrapper for this that knows what is available? What's recommended?
  
  **Tags:** developer
  
  > **Comments:**
  > **username_1**: great question. I am wondering in there is a more definitive answer in 2021: https://chat.civicrm.org/civicrm/pl/xgehp38t7ig88gg5soob3wua1y  
  > **username_2**: are there dev docs or a module that uses CiviCRM's Guzzle which would be useful to an extension author as a reference? the example I found when I looked said `// currently not working` so I won't link to it here!  
  > **username_0**: @ChrisBurgess I don't think Civi needs a copy of [Guzzle's docs](https://docs.guzzlephp.org/en/6.5/)?  
  > **username_2**: true :) [example](https://github.com/civicrm/civicrm-core/blob/5db0bc3c1f54eaca4307f103a73bda596ae914d6/CRM/Utils/Check/Component.php#L134-L145)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2021-08-12. Score: 6 | Accepted answer
  
  CiviCRM core has bundled in Guzzle for a few years now (this was an old issue that got highlighted just now) - so Guzzle is the recommended approach
  
  
  ---
  
  ### Answer by username_2 on 2017-06-01. Score: 3
  
  EDIT: **See Eileen's updated answer above, this is now outdated.**
  
  As of 2021 CiviCRM bundles Guzzle!
  
  ---
  
  I'm unsure what's *recommended*, but there are several patterns (at least) through the codebase:
  
  * [`CRM_Utils_HttpClient`](https://github.com/civicrm/civicrm-core/blob/d799e82070e2319bb5b2e580fabf90f64f907010/CRM/Utils/HttpClient.php), used in core functionality like system checks. This has test coverage!
  * PHP [`curl`](http://php.net/manual/en/book.curl.php), common in the payment processors.
  * PEAR HTTP\_Request, in older code like [geocoders](https://github.com/civicrm/civicrm-core/blob/294ea01475fbdce67534f6759307c80e19fad497/CRM/Utils/Geocode/Yahoo.php).
  * Occasionally [`file_get_contents()`](https://github.com/civicrm/civicrm-core/blob/648631cd94799e87fe2347487d465b1a7256aa57/CRM/Utils/Check/Component/Security.php#L335) to switch things up for fun?
  
  > **Comments:**
  > **username_3**: I downvoted this because it was the right answer at the time but 2021 !== 2018  
  
  ---
  
  