Search code examples
phpxmlrssdomdocumentreddit

Reddit RSS feed returning less items when requested through HTTP?


I am trying to read data from an RSS feed which has 25 items. When I request the RSS file through HTTP it says there are only 20 items.

function test($location)
{
    $doc = new DomDocument();
    $doc->load($location);
    $items = $doc->getElementsByTagName('item');
    return $items->length;
}

// Prints 20
echo test('http://www.reddit.com/r/programming/new/.rss?after=t3_');

// Prints 25
echo test('programming.xml');

I've tried RSS feeds from other subreddits as well with the same result.


Solution

  • I see what the issue is now... If you visit a sub-reddit like /r/programming/ and go to the "new" tab to see newest submissions, there are two sorting options. The first option is "rising" which only shows up-and-coming entries, the alternate sort order is "new".

    Since I chose the "new" sort order in my browser it saved a cookie and was used as the default sort order afterwards. However, accessing the page through code was still using the default sort order, which returned a variable amount of results.

    I resolved the issue by appending the sort order query string to the request url: http://www.reddit.com/r/programming/new/.rss?sort=new