rarebit Posted September 16, 2008 Share Posted September 16, 2008 I'm doing an RSS aggregater, which method of fetching the page is better? if($xml = simplexml_load_string(file_get_contents($stream))) { $sret .= rss_do_rss($xml); } or if($stream = fopen($link, 'r')) { $xml = simplexml_load_string(stream_get_contents($stream)); fclose($stream); $sret .= rss_do_rss($xml); } i.e. which method gets blocked by hosts, more error prone, etc... Link to comment https://forums.phpfreaks.com/topic/124508-solved-which-is-better-method-to-use/ Share on other sites More sharing options...
JonnoTheDev Posted September 16, 2008 Share Posted September 16, 2008 file_get_contents() will return false on error. An error of level E_WARNING is generated using fopen() and will return false however you can supress errors with @fopen(). fopen() will not work if allow_url_fopen is set to false in the remote server php configuration (if they are using php). This is unlikely to be the case if it is an RSS feed. I would ammend your code structure using file_get_contents() to store in a variable first. If the variable has a string length then continue with your aggregation. Link to comment https://forums.phpfreaks.com/topic/124508-solved-which-is-better-method-to-use/#findComment-643003 Share on other sites More sharing options...
rarebit Posted September 16, 2008 Author Share Posted September 16, 2008 It was the fopen bit I was trying to remember, thanks v mucho! Link to comment https://forums.phpfreaks.com/topic/124508-solved-which-is-better-method-to-use/#findComment-643101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.