0

I created my own feed for my website and connected it to feedburner and to dlvr.it for dissemination to social media sites.

However, whenever I create a new post in my site, it takes a few minutes to post to feedburner (which is not really a problem) and it does not post updates to my social media accounts and upon viewing dlvr.it's reports, it says 'no items found via pull'

My complete code for my xml which is connected to feedburner goes like this:

 <?php
include('db.php');

header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="ISO-8859-1"?>  
<rss version="2.0">  
<channel>  
<title>MindWeather Thesis</title>  
<description>Latest News from my website</description>  
<link>http://www.MySite.info</link>';  

$get_articles = "SELECT ID, NewsType, Content,   
DATE_FORMAT(DateTime,'%a, %e %b %Y %T') as formatted_date   
FROM tblnews ORDER BY DateTime DESC LIMIT 15";  

$articles = mysql_query($get_articles) or die(mysql_error());  

while ($article = mysql_fetch_array($articles)){  

    echo '  
       <item>  
          <title>'.$article['NewsType'].'</title>  
          <description><![CDATA['.$article['Content'].']]></description>  
          <link>http://www.MySite.info</link>  
          <pubDate>'.$article['formatted_date'].' GMT</pubDate>  
      </item>';  
} 
echo '</channel>
</rss>';
?>

What's wrong?

Sarah
  • 117
  • 1
  • 9
  • I have the impression that you've disabled PHP error reporting (or lowered it to a level where it's useless for development). Additionally, you don't care escaping input data so it'll break the feed (which is not valid anyway) as soon as it contains `<`, `>` or anything like that. – Álvaro González Dec 30 '13 at 09:27
  • Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). The error reporting thumb rule is: show in development, log in production. – Álvaro González Jan 03 '14 at 08:05

1 Answers1

0

First of all, move the header() call up before your first echo(). You should always output headers before any other output, because they put information into the HTTP header, which should always be complete before the actual body starts appearing. As it says in the manual:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Second, let's have a look at the output you're generating. You've not provided the output from your PHP (FeedBurner changes things on the way through to try to help make feeds more valid/useful), but this is roughly what you're generating, assuming a single item in the database:

<?xml version='1.0' encoding='ISO-8859-1' ?>
<rss version='2.0'>
Mindweather
  <channel>http://www.MySite.info
    <title>MyProj</title>
    <item>
      <title>NewsType</title>
      <link>http://www.MySite.info/signin.ph</link>
      <description>Content</description>
    </item>
    <link>MyProj/link>
  </channel>
</rss> 

So, there's a few problems there. You can compare your output with the RSS spec, or run it through the W3 Feed Validator Service to get some tips, or even compare your feed to a basic example, like the one on Wikipedia, but basically:

  • The word "Mindweather" appears in an invalid place. Remove it, or move it where it needs to be. Is it the title of the feed? If so, it should be where "MyProj" is, in the <title> of the <channel>.

  • "http://www.MySite.info" appears in an invalid place. If that's meant to be a link to your site, it should be in the <link> element of the <channel>, near the end, where you have echo "<link>MyProj/link>

  • (While I'm there, you're missing the open angle bracket from the </link> on that line, too.)

  • Your <channel>'s <link> element should be before all your items.

  • Your <channel> needs a <description> element.

On top of that, you don't have a pubDate or a guid element in your feed.

Even though pubDate and guid are technically optional, things that regularly pull content from RSS feeds tend to look for one or both of them to see if they've seen them before or not. The pubDate should be the publication date of the new item, and the guid should be a unique identifier for it (often the URL of the specific item is used.) See the RSS 2.0 spec for more details.

For example, often something that's pulling from a feed will only pick up items from the last 30 days, say, so it'll look for any items with a pubDate more recent than that. If none of your items have a pubDate, it won't "see" any of them.

When I'm developing a feed, I'll generally grab an example as a template and make my output look like that, only with my details in it.

Finally, bear in mind that the mysql extension is deprecated, and will be removed from future versions of PHP. You shouldn't be using it for new code.

Community
  • 1
  • 1
Matt Gibson
  • 37,886
  • 9
  • 99
  • 128
  • Ah, okay -- it's worse than I thought. Check the errors that the Feed Validator gives [for your feed](http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Ffeeds.feedburner.com%2FMindweatherThesis); I'll update my answer with some more details when I've had breakfast :) Also: can you get us the *original* feed XML that you passed to Feedburner? It looks like Feedburner is trying to clean up your RSS by inserting pubDates for you, but they're all in 1969! – Matt Gibson Dec 30 '13 at 08:33
  • Hi! I lost my internet for the past few days due to the network's probs. Anyway, thanks for your reply. I have updated my xml code (see updated code in the question) and the xml that is passed to feedburner is http://www.mindweather.info/feeding.php – Sarah Jan 02 '14 at 03:24
  • I have updated my code. I worked through it and finally got a valid rss (see updated code above or view http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.mindweather.info%2Ffeedz.php) I have set dlvr.it to post 10 posts every 30 mins but it posted only one (though it says 10 posts found via pull, 10 posted). What else is wrong? – Sarah Jan 08 '14 at 10:20