Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.