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
https://forums.phpfreaks.com/topic/136257-rss-feed-error-while-fsockopen/
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!

 

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) ) {

.....

}

 

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..";

}

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

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!

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!

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.