public static function pullFeed($id) { $oFeed = Feed::find($id); if (isset($oFeed)) { try { echo "pulling: ", $oFeed->url, "<br/>"; // get the guid of the last pulled item so we know where to stop $oFeedItem = $oFeed->feedItems->first(); // stop at null, unless we have some feed items already, then stop at most recent $sStopAt = null; if (isset($oFeedItem)) { // there are already items from this feed $sStopAt = $oFeedItem->guid; } $context = stream_context_create(array('http' => array('header' => 'Accept: application/xml'))); $xmlFeed = @file_get_contents($oFeed->url, false, $context); $iItemsFetched = 0; if (!empty($xmlFeed)) { $oScrapedFeed = Helper::getFeedStructureFromXML($oFeed, $xmlFeed, $sStopAt); $iItemsFetched += count($oScrapedFeed->aoItems); if (isset($oScrapedFeed->thumb)) { $oFeed->thumb = $oScrapedFeed->thumb; } } else { // todo: failed to fetch feed } $oFeed->lastPulledCount = $iItemsFetched; $oFeed->hit_count = $oFeed->hit_count + 1; $oFeed->item_count = $oFeed->item_count + $iItemsFetched; $mytime = Carbon::now(); $oFeed->lastPulled = $mytime->toDateTimeString(); $oFeed->save(); } catch (Exception $e) { echo "fetching feed (", $oFeed->id, ") ", $oFeed->url, " failed", "<br/>"; } } }