Jump to content

RSS Feed error while fsockopen


freephoneid

Recommended Posts

Hi,

    I want to display RSS feed in a marquee ticker.

 

Feed URL: http://www.wired.com/news/feeds/rss2/0,2610,,00.xml

 

I'm trying to fetch contents using following command:

 

$fp = fsockopen($host, $port, $errno, $errstr, 2)

 

But, I'm getting error:

"Failed to Get RSS Data

An error was ecnountered attempting to get the RSS data: An unknown error occurred."

 

Can any one help me how to fetch xml from this feed url? Can any one provide me the details?

 

Thanks in Advance!

 

Link to comment
Share on other sites

Thanks! I saw that article but I would like to know why the below connection is not happening?

 

$host = "rss.news.yahoo.com";

$uri = "/rss/topstories";

 

$request = "GET " . $uri . " HTTP/1.0\r\n";

$request .= "Host: " . $host . "\r\n";

$request .= "Connection: close\r\n\r\n";

 

if( $http = fsockopen($host, 80, $errno, $errstr, 5) ) {

.....

}

 

Code gives error while opening socket....Can you please help?

 

Thanks!

 

Link to comment
Share on other sites

Yes, I've checked & allow_url_open is On. But allow_url_include was Off, so I tried with that On

as well but still no luck!

 

Please help!

 

Why the below code not working?

 

$host    = "rss.news.yahoo.com";

$uri    = "/rss/topstories";

 

$request = "GET " . $uri . " HTTP/1.0\r\n";

$request .= "Host: " . $host . "\r\n";

$request .= "Connection: close\r\n\r\n";

 

if( $http = fsockopen($host, 80, $errno, $errstr, 5) ) {

.....

}

 

Link to comment
Share on other sites

can any one try below code at yr end n see if it works?

 

$host    = "rss.news.yahoo.com";

$uri    = "/rss/topstories";

 

$request = "GET " . $uri . " HTTP/1.0\r\n";

$request .= "Host: " . $host . "\r\n";

$request .= "Connection: close\r\n\r\n";

 

if( $http = fsockopen($host, 80, $errno, $errstr, 5) ) {

  echo "hurray..";

}

Link to comment
Share on other sites

I'm not sure. I'm always a bit uncomfortable with remote files. Could be something in php.ini. Could be something with your ISP... Got no idea.

 

Also note, that while it displays "Hooray", it will timeout when I add

$foo = fread($http,10); 
echo $foo;

after that

Link to comment
Share on other sites

okay....even the below code does not work for me?

 

<?php

$xml="http://news.google.com/news?ned=us&topic=h&output=rss";
$xmlDoc = new DOMDocument();

$xmlDoc->load($xml);//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;//output elements from <channel>"

echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++) {
	$item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
	$item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
	$item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue; echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>");
	echo ("<br />");
	echo ($item_desc . "</p>");
}

?>

 

Gives error :

failed to open stream: A connection attempt failed because the connected party did not properly respond ....

 

Can any one help?

 

Thanks!

Link to comment
Share on other sites

Nope......same error:

 

SimpleXMLElement::__construct(http://news.google.com/news?ned=us&topic=h&output=rss) [<a href='function.SimpleXMLElement---construct'>function.SimpleXMLElement---construct</a>]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\r\n in C:\\aa.php on line 4

 

Please help!

Link to comment
Share on other sites

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.