I have a simple file download service written in PHP, which also includes a script that controls the download speed by sending packets with a limited size when the user requests a download from this site.
I want to implement a system to limit parallel / simultaneous loading to 1 per user, if they are not participants in the award. In the downloadable script above, I can use the MySQL database to store a record that has: (1) user ID; (2) file identifier; (3) when starting the download; and (4) when sending the last packet, which is updated every time it is performed (if the DL speed is limited to 150 kB / s, then after every 150 kB this record is updated, etc.).
However, until now, the database record will be deleted only after the download is complete - at the end of the script, after the full download, the record download is deleted from the table:
insert DB record; while (download is being served) { serve packet of data; update DB record with current date/time; } // Download is now complete delete DB record;
How can I detect when the download was canceled? Should I just have a Cron job (or something similar) to detect if the existing download record is more than X minutes / hours? Or is there something else I can do that is missing?
I hope I explained it quite well. I do not think that it is required to send a specific code; I'm more interested in the logistics of how to do this. If necessary, I gladly provided it.
NOTE. I know how to determine if a file was uploaded successfully; I need to know how to determine if it has been canceled, interrupted or otherwise stopped (and not just suspended). This will be useful to stop concurrent downloads, as well as to prevent the user from canceling download # 1 and trying to start Download # 2, only to find that the site claims that it is still downloading file # 1.
EDIT: you can find my download script here: http://codetidy.com/1319/ - it already supports multi-user downloads and resume downloads.
source share