rares_dumitrescu
asked on
How can i keep track of file downloads
I need to keep an exact track of file downloads. Plus, if a user cancels the download before it ends i dont want it to be counted.
Do you know any script that does this ? (it would be best if the script were written in PHP)
Do you know any script that does this ? (it would be best if the script were written in PHP)
Hey There ...
I need some information before i can guide you something
1. OS .
2. Any specfic downloads you wanna monitor or all of em .
Confirm me these details..
Anuj Bhatia
ASKER
The downloads will be made from a website, running on PHP, on apache/nginx with linux (centos i think)
And no, i dont want to monitor any specific downloads, i want to monitor any type of file. I want to make a website like rapidupload or something like that
And no, i dont want to monitor any specific downloads, i want to monitor any type of file. I want to make a website like rapidupload or something like that
The Apache access log can detail every file retrieved and the number of bytes transfered, see: http://httpd.apache.org/docs/current/mod/mod_log_config.html
As to canceled download, you could write something to compare the file sizes on disk to that in the logs, and if different flag the entry as failed, but may need to work out the zipped size first.
As to canceled download, you could write something to compare the file sizes on disk to that in the logs, and if different flag the entry as failed, but may need to work out the zipped size first.
"if a user cancels the download before it ends i dont want it to be counted."
On a web site, it can't be done. There is no "end-of-download" signal defined in HTTP. You might be able to make something that would catch this situation in FTP, but that is just a guess.
OTOH, keeping track of REQUESTED downloads is easy - just log all the requests into a data base.
On a web site, it can't be done. There is no "end-of-download" signal defined in HTTP. You might be able to make something that would catch this situation in FTP, but that is just a guess.
OTOH, keeping track of REQUESTED downloads is easy - just log all the requests into a data base.
Looks like Apache will flag failed / canceled download (requests), as long as you add the %X to the LogFormat command.
If you want the information available to your application you'll need want to write the logs to a Database e.g. MySQL see:
http://www.outoforder.cc/projects/apache/mod_log_sql/docs-2.0/
http://onlamp.com/pub/a/apache/2005/02/10/database_logs.html
If you want the information available to your application you'll need want to write the logs to a Database e.g. MySQL see:
http://www.outoforder.cc/projects/apache/mod_log_sql/docs-2.0/
http://onlamp.com/pub/a/apache/2005/02/10/database_logs.html
@arober11: That's interesting. I would like to see it in action, especially if the download was created by a link like <a href>. Is there any way you know of to get this information contemporaneously in a PHP script?
Thanks, ~Ray
Thanks, ~Ray
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Cool, thanks!
Could simplify the grep's slightly e.g.
$grepit="$grep -c '\"GET $theFile.*$theSession.*\\+ \$' $logFile ";
AND:
$grepit="$grep -c '\"GET $theFile.*$theSession.*X\$ ' $logFile ";
$grepit="$grep -c '\"GET $theFile.*$theSession.*\\+
AND:
$grepit="$grep -c '\"GET $theFile.*$theSession.*X\$
ASKER
that is so cool! thank you arober11
As far as incomplete downloads are concerned, that's a bit trickier. I can't think of a way to automatically tell, but you could pop a window and ask them to close it when the download is complete. But there's no way to be sure they'll close it correctly.