Jump to content

[SOLVED] Which is better method to use?


rarebit

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.