Jump to content

Total Uploaded / Download Statistics (++) [PHP]


Recommended Posts


One of the features I've been missing the mosts from the usual uT client, is the possibility to view some basic statistics (like how much has been downloaded totally over time).

Seeing as how I'm yet to find anyone implementing these features into their UI / Application, I decided to atleast work out a simple php script that just outputs this information on a blank page.

Now what I very much would your input on, is how do we solve the persistency problem? Seeing as how the information we get with the script is currently just fetched by iterating through all the added torrents, and then simply just summing up the amount download / uploaded on each of them.

But what I want is being able to keep track of an "absolute total", meaning also all the bytes that have been download / uploaded by torrents, including those that have been removed from the client.

Any ideas on how we solve that? Simple file storage? Or do some database interaction? =)

Here is my script, which is utilizing the PHP API:


require_once 'api.php';

function ByteCalc ($bytes) {
$size = $bytes / 1024;
if ($size < 1024) {
$size = number_format($size, 2);
$size .= ' KB';
} else {
if ($size / 1024 < 1024) {
$size = number_format($size / 1024, 2);
$size .= ' MB';
} elseif ($size / 1024 / 1024 < 1024) {
$size = number_format($size / 1024 / 1024, 2);
$size .= ' GB';
return $size;

$client = new uTorrent('HOST', 'PORT', 'USERNAME', 'PASS');

$torrents = $client->getTorrents();

$downTotal = 0;
$upTotal = 0;

foreach ($torrents as $torrent) {
$downTotal += $torrent[UTORRENT_TORRENT_DOWNLOADED];
$upTotal += $torrent[UTORRENT_TORRENT_UPLOADED];

echo "<b>Total downloaded:</b> " . ByteCalc($downTotal);
echo "<br/>";
echo "<b>Total uploaded:</b> " . ByteCalc($upTotal);

Link to comment
Share on other sites

Reading settings.dat would require that the PHP script runs on the same server as µTorrent, which may not always be the case. The best action would be for µTorrent to allow clients to request this data (or maybe just send the data with /gui/?action=getsettings, or something).

There is no reliable way to determine total transfer counts via WebUI.

Link to comment
Share on other sites

Ultima is right.

The php would have to run on the same machine as µtorrent or at least have physical access to the settings.dat file.

Then you could use DeHackEd's beencode php class. Of which a slightly modified version is on the utorrent trac (as part of the Webui-Shell). I couldn't quickly find the original.

Then you could use something like the following code (just an example):

if ( file_exists($settingsdat) )
if ( is_readable($settingsdat) )
$decode = new BDecode;
$readfile = $decode->decodeDict(file_get_contents($settingsdat));
$td = bytes($readfile[0]["td"]);
$tu = bytes($readfile[0]["tu"]);
$getdate = date('Y.m.d. H:i:s');
echo '<b>Total Down:</b> '.$td.' <b>Total Up:</b> '.$tu.' <b>Date:</b> '.$getdate;

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...


This topic is now archived and is closed to further replies.

  • Create New...