How to count your Drupal website RSS subscribers?

Website owners using Drupal have a very detailed log of access available directly in their admin pages. However there is no built-in functionality which could show how many RSS subscribers does the website have. You have all the neccessary information available in the log. So only thing you have to do is to find them and to show them. I will show you how to prepare a block that will inform you and your readers about current RSS subscribers count.

RSS subscribers block in Drupal

So at first, create a new block and set up its input format to the PHP code. You should input a few sentences to your readers about RSS. Then prepare the most important part of this work - SQL command:

<?php
$rssreaders = db_fetch_array(db_query("SELECT COUNT(DISTINCT(hostname)) AS hostname FROM {accesslog} WHERE path LIKE '%/feed' OR path LIKE 'rss.xml'"));
?>

This command will count all RSS hits to the URL's ending by /feed or to rss.xml page. The DISTINCT keyword will manage to count every IP in the accesslog only once. Then you have to print the value in $rssreaders['hostname'] somewhere:

<p>Follow other readers and <a href="/rss.xml">subscribe</a> to our <a href="/rss.xml">RSS feed</a>. Currently we have <b><?php print $rssreaders['hostname']; ?></b> RSS subscribers now.</p>

So the result content of your block should look like this:

<?php
$rssreaders = db_fetch_array(db_query("SELECT COUNT(DISTINCT(hostname)) AS hostname FROM {accesslog} WHERE path LIKE '%/feed' OR path LIKE 'rss.xml'"));
?>
<p>Follow other readers and <a href="/rss.xml">subscribe</a> to our <a href="/rss.xml">RSS feed</a>. Currently we have <b><?php print $rssreaders['hostname']; ?></b> RSS subscribers now.</p>

I have use this block on my websites Backup HowTo and Photo HowTo - take a look if you are interested.