April 16, 2009 by Eric Heikkinen | 2 Comments »
Pligg Download Counter
The other day I was curious to figure out how many downloads Pligg has had, or at least how many we were able to officially track. I ended up writing a PHP script to track the official Pligg downloads from the forums and to add in some old download data from Sourceforge. What saddens me is that I can’t track a lot of third-party sites out there and one-click installs provided by web hosts, so this number might be off by quite a bit. Some of you might find it interesting on how we are now tracking our downloads and how you can use our download count, so I’ll be documenting all of that on this post.
First, let me explain how the stats work by giving you some example URLs that you can use to fetch download counts. The main url http://www.pligg.com/download_count.php gives you the total number of downloads that we are able to track. Now if you add some parameters to this URL you can get the stats for the average downloads per hour, week, day or year. Here’s an example of the day average url: http://www.pligg.com/download_count.php?stat=day.
The numbers being generated here are updated a couple times an hour, so you won’t see the download count increasing with each page refresh. I bet your asking yourself how this number is being generated, well it’s a mix of hard-coded numbers and numbers that are continually being fetched from the vBulletin forum MySQL database. We used to use a downloads section of the site for hosting Pligg over a year ago, but since we switched that part of the site off the old versions of Pligg are no longer available. Since users can’t download them we know that the number for those versions isn’t going to change so we added up those numbers. Then we wrote a script that connects to the MySQL database and finds the download count for all of the working downloads from the Current Version forum. Then we add all of those numbers up into one figure representing Pligg.com downloads. I then hard coded some download figures provided by sourceforge.net and softpedia.com for some of our older versions and added them to the total figure. The end result of all of these numbers is our total download count.
To generate an average daily count I wanted to discard a lot of the older download data since it wasn’t tracked very well and decided to only calculate the number of downloads from Pligg RC1 or newer. I took the total number of release candidate versions and then divided them by the number of days between the current date and the release date for RC1. The end result gives you an average daily download number (rounded to the nearest whole number) which the average hourly, monthly and yearly stats are based on.
<?php
$downloadcount = file_get_contents('http://www.pligg.com/download_count.php');
echo $downloadcount;
?>
Above is a quick example of how you could use PHP to grab the download number inside of a PHP script to display the number. We are using this method to display the Download Stats currently found at the top right of the Pligg Blog. If you are interested in the complete source code for this download counter script designed for vBulletin sites, please view the full article URL for the PHP source.
Read the rest of this entry » 







