projects
/
ambdownload.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add file time/speed; make URLs configurable in Wordpress
[ambdownload.git]
/
download.pl
diff --git
a/download.pl
b/download.pl
index
af11039
..
859d5d8
100755
(executable)
--- a/
download.pl
+++ b/
download.pl
@@
-7,12
+7,14
@@
use POSIX qw(strftime);
use URI::Escape;
use File::Copy qw( copy );
use File::Basename;
use URI::Escape;
use File::Copy qw( copy );
use File::Basename;
+use File::stat;
use Digest::SHA qw(sha256_hex sha1);
use MIME::Base64;
use File::Spec;
use CGI;
use HTML::Entities;
use IO::Handle;
use Digest::SHA qw(sha256_hex sha1);
use MIME::Base64;
use File::Spec;
use CGI;
use HTML::Entities;
use IO::Handle;
+use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
my $log;
my $transaction="unknown";
my $log;
my $transaction="unknown";
@@
-140,6
+142,9
@@
else
{
openlog;
my $file = decodeparams;
{
openlog;
my $file = decodeparams;
+ my $sb = stat($file);
+ my $size = $sb->size;
+ my $t0 = [gettimeofday];
lprintf("STARTING\n");
$SIG{INT} = \&caughtsignal;
$SIG{QUIT} = \&caughtsignal;
lprintf("STARTING\n");
$SIG{INT} = \&caughtsignal;
$SIG{QUIT} = \&caughtsignal;
@@
-148,7
+153,8
@@
else
$SIG{KILL} = \&caughtsignal;
$SIG{TERM} = \&caughtsignal;
sendfile($file);
$SIG{KILL} = \&caughtsignal;
$SIG{TERM} = \&caughtsignal;
sendfile($file);
- lprintf("SUCCESS\n");
+ my $elapsed = tv_interval ( $t0, [gettimeofday]);
+ lprintf("SUCCESS %d bytes %.3f MB/s\n", $size, $size/(1000000.0*(($elapsed<0.001)?0.001:$elapsed)));
closelog;
exit(0);
closelog;
exit(0);