Skip to content

Instantly share code, notes, and snippets.

@dambridge
Forked from james2doyle/laravel-blog-rss-read.php
Created September 7, 2016 20:49
Show Gist options
  • Select an option

  • Save dambridge/b1e5668e057475ba748577e7752be646 to your computer and use it in GitHub Desktop.

Select an option

Save dambridge/b1e5668e057475ba748577e7752be646 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