0

I need to deliver 2 GB files to clients (who receive a personal download token), I currently use this:

if (is_valid_download_token($token)) {
    log_download_start();  // logs token, date, IP
    header("X-Sendfile: /files/2GB_file.zip");
    header("Content-type: application/octet-stream");
    header('Content-Disposition: attachment; filename="2GB_file.zip"');
}

I'd like my automated system to make sure:

  • that they downloaded the file successfully at least once (I periodically run a script to check this)
  • that there is no more than 2 successful downloads for a given token (after this, I'll return a message)

Thus, how to get the number of successful downloads of a 2 GB file by a client?

Notes on what I've tried so far:

  • Simply incrementing a counter in log_download_start() is not a good solution because someone might have to restart 5 times the download (because of a poor internet connection), until it finally works.

  • Also, from the logs, I know people use "download managers" that split the 2 GB download into 20 download requests of 100 MB, which is totally fine. So just counting the number of requests at the start isn't efficient.

  • I'm using PHP + Apache + X-Sendfile for the specific reasons explained in Fastest Way to Serve a File Using PHP and Downloading files with download.php. TL;DR: I don't want the 2 GB data to be read by PHP (which would slow down everything), instead I let Apache handle the request directly.

Basj
  • 41,386
  • 99
  • 383
  • 673
  • You might be able to spot the failed downloads in the Apache logs - https://stackoverflow.com/questions/60366932/apache2-how-to-log-rejected-connections-and-client-timeout – ADyson Mar 03 '21 at 07:46
  • @ADyson The problem is that if a download manager downloads the part #5 among 20 parts of 100 MB, it would probably be displayed as failed because not the whole 2 GB file is served, but in fact it's part of a successful download. – Basj Mar 03 '21 at 09:48

0 Answers0