Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created November 27, 2015 22:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save james2doyle/fd14ab5711702f28feb3 to your computer and use it in GitHub Desktop.
Save james2doyle/fd14ab5711702f28feb3 to your computer and use it in GitHub Desktop.
Simple Guzzle pattern for reading a RSS Feed. This assumes you are using Laravel or something similar.
<?php
// use GuzzleHttp\Client;
// use Cache;
// 86400 = 1 day // 604800 = 1 week
$feed = Cache::remember('rr-blog', 86400, function()
{
$client = new Client([
'base_uri' => 'https://blog.raceroster.com/',
'timeout' => 2.0,
]);
$response = $client->get('feed/');
$data = $response->getBody()->getContents();
return $data;
});
// you cannot serialize `simplexml_load_string`, so we convert it after
$feed = simplexml_load_string($feed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment