1

I'm trying to count total bandwidth usage per download.

For a example if I'm sending a 100 mb file to a user and the user disconnects/stops downloading half way so actually only 50 mb being used. Is there a way to track this?

I found this example in a tutorial and in a question on sof.

if ($fd = fopen ($fullPath, "r")) {

    //the next part outputs the file
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);

    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=".$path_parts["basename"]."");
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);

and

PHP - determine how many bytes sent over http

Community
  • 1
  • 1
Naveen Gamage
  • 1,844
  • 12
  • 32
  • 51
  • You're sending 2K per iteration of that while loop. So, the simplest solution is to reset a database count for this user at the start of that loop, and increase it by 2K for every iteration. – halfer Nov 08 '13 at 20:21

0 Answers0