DOMDocument::load() while reading RSS

Hi,

I use RSSlib to display news for a RSS feed on my homepage. The code works when Im working on localhost, but fails every time when I go online, onto my server.

The error is:

Warning: DOMDocument::load() [domdocument.load]: Document is empty in [RSS Location], line: 1 in rsslib.php on line 53

This is the code here , up to line 53:



<?php
$RSS_Content = array();

function RSS_Tags($item, $type) {
    $y = array();
    $tnl = $item->getElementsByTagName("title");
    $tnl = $tnl->item(0);
    $title = $tnl->firstChild->textContent;

    $tnl = $item->getElementsByTagName("link");
    $tnl = $tnl->item(0);
    $link = $tnl->firstChild->textContent;

    $tnl = $item->getElementsByTagName("pubDate");
    $tnl = $tnl->item(0);
    $date = $tnl->firstChild->textContent;		

    $tnl = $item->getElementsByTagName("description");
    $tnl = $tnl->item(0);
    $description = $tnl->firstChild->textContent;

    $y["title"] = $title;
    $y["link"] = $link;
    $y["date"] = $date;		
    $y["description"] = $description;
    $y["type"] = $type;

    return $y;
}

function RSS_Channel($channel) {
    global $RSS_Content;

    $items = $channel->getElementsByTagName("item");
    
    // Processing channel
    
    $y = RSS_Tags($channel, 0);		// get description of channel, type 0
    array_push($RSS_Content, $y);
    
    // Processing articles
    
    foreach($items as $item) {
        $y = RSS_Tags($item, 1);	// get description of article, type 1
        array_push($RSS_Content, $y);
    }
}

function RSS_Retrieve($url) {
    global $RSS_Content;

    $doc  = new DOMDocument();
    $doc->load($url);

...


RSS_Retrieve() is called later on with the URL of the RSS feed.

What would cause this to work offline on a personal server, but fail online?

So I tried with a different RSS feed, and it works.

I wonder, do websites block IPs that read their RSS feeds…?

You need to do more debugging and see what exactly is retreived from the rss url. Maybe it’s not empty but instead some invalid xml is returned.

Block ip for rss does not make much sense, but of cause it’s a possibility. If a website finds out that you use their rss feed in violation of their terms of service, they could block your ip.

I just switched over to the MagpieRSS suite and it works and offers better error handling. Cheers