2011-11-22 82 views
2

我有這個Perl/CGI上傳文件並獲取上傳的文件大小。大量上傳Perl/CGI腳本失敗

對於500MB以下的文件,該腳本工作正常,但緩衝區(OUTFILE)在大約500MB後停止寫入文件。 這裏的部分代碼:

$u_size = $ENV{'CONTENT_LENGTH'}; 
if ($u_size > $max_size) {send_error ("Upload too big. Maximum size is $max_size bytes and your file is $u_size bytes.");} 

print_progress(0); 
# Set up uploading function 
$query = CGI->new(\&hook); 

#define functions 
sub hook { 
    if ($error) {return;} 
    if (time >= $next_print) { 
     $next_print = time + $delay; 
     my ($filename, $buffer, $bytes_read, $data) = @_; 
     if ($check_mime) { 
      $filename =~ m/\.([^\.]+)$/; 
      $ext = lc($1); 
      print $ext; 
      $check_mime = 0; 
     } 
     $percent = $bytes_read/$u_size; 
     $filename =~ m/\\([^\\]+)$/; 
     $filename = $1; 
     print_progress($percent, $u_size, $bytes_read, $filename); 
    } 
} 

sub print_progress { 
    open(PROG, '>'.$uploaded_file_progress); 
    print PROG '{"percent" : ' . ($_[0] * 100) . ', "total" : ' . $_[1] . ', "uploaded" : ' . $_[2] . ', "filename" : "' . $_[3] . '"}'; 
    close PROG; 
} 

############# 

$uphandle = $query->upload($query->param()); 
binmode $uphandle; 

if (!$error) { 
    open OUTFILE, ">" . $uploaded_file; 
    binmode OUTFILE; 
    while($bytesread = read $uphandle, $buffer, 1024) { 
     print OUTFILE $buffer; 
    } 
    #while (<$uphandle>) {print OUTFILE $_;} 
    close OUTFILE; 
} 

如果腳本是沒有問題的,還有什麼其他的東西,我要檢查? 謝謝。

編輯:我在日誌中:超時等待CGI腳本的輸出。 我該如何擺脫這種情況?我無法在Google上找到明確的答案。

回答

2

我想象你需要在apache conf中戳你的apache TimeOut配置變量。

看到你正在使用perl,這已經在perlmonks.org上被引用了幾次,並且這個鏈接已經彈出來作爲迴應。

http://www.stonehenge.com/merlyn/LinuxMag/col39.html

+0

感謝您指導'TimeOut'配置。這是兩臺服務器上唯一不同的東西。我不敢相信這很簡單。 – user173457

1

您可能希望將$ CGI :: POSTMAX設置爲大於500MB的值,以查看是否更正了此問題。

如果我沒有弄錯,500MB是POSTMAX的默認值。我總是把它設置爲2GB(但是我用它來上傳很多視頻!)

0

有一個Apache httpd.conf'MaxRequestLen'設置值得研究(如果您使用的是Apache)。