Created
November 27, 2015 22:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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