PHP
Article

Watch: Fetch Remote Data Using Guzzle

By Ashraff Hathibelagal

Fetching data from a remote server has become a very common task these days. Unless you are very new to web programming, you must have, at some point, written code to fetch something from a remote server, be it JSON, XML, text or even an image. Most PHP developers are used to using cURL to perform such tasks. However, there’s a better alternative: the Guzzle HTTP client. It has a more intuitive API, and using it means writing less code.

In this screencast, I’m going to show you how to download an RSS feed using Guzzle. You can find the code sample for this screencast on GitHub.

Loading the player…

  • Sam Wong

    From the guzzle docs, we actually can use below code to parse XML as SimpleXMLElement object
    $xml = $response->xml();
    echo $xml->foo;

    • Yifon

      I think you read Guzzle 3’s documentation. Guzzle 6 doesn’t have any such method.

      • Sam Wong

        Ooops! Thanks for clarifying. My bad.

      • Sam Wong

        Ooops! Thanks for clarifying. My bad.

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in PHP, once a week, for free.