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.