Perl/CGI 脚本在大量上传时失败

标签 perl upload cgi large-files

我有这个 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;
}

如果脚本没有问题,我还需要检查哪些其他内容?
谢谢。

编辑:我在日志中有这个:WAITING CGI 脚本输出的超时。
我该如何摆脱这个?我在谷歌上找不到明确的答案。

最佳答案

我想你需要戳你的 apache TimeOut apache conf 中的配置变量。

看到您正在使用 perl,这已在 perlmonks.org 上提出过几次,并且已弹出此链接作为回应。

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

关于Perl/CGI 脚本在大量上传时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8221174/

相关文章:

perl - 这是在 Perl 中提取 AoH 子集的最干净的方法吗?

java - 如何将绝对路径转换为相对路径,以便可以从 img 标签引用它? java网络

c# - 将文件上传到 asp.net 中的 ftp 文件夹

perl - 为什么 Perl 常用于编写 CGI 脚本?

cgi - 配置 lighttpd 以处理 CGI C 可执行文件

python - 如何读取 Python CGI 脚本中的所有 HTTP header ?

java - 用双引号封装时转义序列与预定义字符类(也称为特殊正则表达式字符)

perl - 如何使用证明在不同的服务器上运行相同的测试?

arrays - 我可以将看起来像数组内容的字符串转换为数组吗?

node.js - Express NodeJS 服务器中的 HTTP 文件上传