Aug 4, 2010
Usu

How to automatically update your FeedBurner RSS using cURL

FeedBurner is a pretty cool service that provides insights and many other useful information about the RSS Feed of a website, though if you need your users to be notified immediately after a new item is posted on the website you’ll find that there is a nasty limitation in place: the feed is only updated every 30 minutes.

Fortunately FeedBurner also provides a ping service that let you manually update your RSS Feed; but visiting a website every time you need to update your feed isn’t very practical, instead we can use cURL to do this automatically every time we publish a new article or something.

Here’s the PHP code (you need to make sure that your hosting has cURL enabled):

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'http://feedburner.google.com/fb/a/pingSubmit');
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, 'bloglink=http://www.example.com');
$result = curl_exec($ch2);
curl_close($ch2);

You need to place this right after the code that publishes a new item on your website, so that the RSS Feed is immediately updated with the new articles (or whatever you are publishing).

Another way to do this is by putting the code in a cronjob and run it every X minutes, but use this only if you can’t get  the other method working, it’s way better.

Here’s the code to use cURL directly from the command line (use this if you are planning to go with the cronjob method):

curl -d 'bloglink=http://www.example.com' http://feedburner.google.com/fb/a/pingSubmit

Also you don’t need to provide the full RSS Feed URL, the website base URL will do just fine.

Leave a comment