From 2dc8f8bdc8f4b76c99b94fef78ee6879dac10c38 Mon Sep 17 00:00:00 2001 From: Allan Kristensen Date: Wed, 26 Feb 2014 15:26:37 +0100 Subject: [PATCH] Improve file upload speed --- web-lib-funcs.pl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index b24ef2716..000cecc0d 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -511,7 +511,7 @@ and store it in the global %in hash. The optional parameters are : sub ReadParseMime { my ($max, $cbfunc, $cbargs) = @_; -my ($boundary, $line, $foo, $name, $got, $file); +my ($boundary, $line, $foo, $name, $got, $file, $count_lines, $max_lines); my $err = &text('readparse_max', $max); $ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/ || &error($text{'readparse_enc'}); if ($ENV{'CONTENT_LENGTH'} && $max && $ENV{'CONTENT_LENGTH'} > $max) { @@ -519,6 +519,8 @@ if ($ENV{'CONTENT_LENGTH'} && $max && $ENV{'CONTENT_LENGTH'} > $max) { } &$cbfunc(0, $ENV{'CONTENT_LENGTH'}, $file, @$cbargs) if ($cbfunc); $boundary = $1; +$count_lines = 0; +$max_lines = 1000; ; # skip first boundary while(1) { $name = ""; @@ -569,8 +571,12 @@ while(1) { while(1) { $line = ; $got += length($line); - &$cbfunc($got, $ENV{'CONTENT_LENGTH'}, $file, @$cbargs) - if ($cbfunc); + $count_lines++; + if ($count_lines == $max_lines) { + &$cbfunc($got, $ENV{'CONTENT_LENGTH'}, $file, @$cbargs) + if ($cbfunc); + $count_lines = 0; + } if ($max && $got > $max) { #print STDERR "over limit of $max\n"; #&error($err); @@ -581,8 +587,6 @@ while(1) { if ($cbfunc); return; } - my $ptline = $line; - $ptline =~ s/[^a-zA-Z0-9\-]/\./g; if (index($line, $boundary) != -1) { last; } $in{$name} .= $line; }