Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl/CGI脚本在大型上载时失败_Perl_Upload_Cgi_Large Files - Fatal编程技术网

Perl/CGI脚本在大型上载时失败

Perl/CGI脚本在大型上载时失败,perl,upload,cgi,large-files,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.");

我使用这个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;
}
$u_size=$ENV{'CONTENT_LENGTH'};
如果($u_size>$max_size){send_错误(“上载太大。最大大小为$max_size字节,而您的文件为$u_size字节。”);}
打印进度(0);
#设置上传功能
$query=CGI->new(\&hook);
#定义函数
副钩{
if($error){return;}
如果(时间>=$next\u打印){
$next_print=时间+$delay;
我的($filename,$buffer,$bytes\u read,$data)=@;
如果($check\u mime){
$filename=~m/\.([^\.]+)$/;
$ext=lc$1;
打印$ext;
$check_mime=0;
}
$percent=$bytes\u read/$u size;
$filename=~m/\\([^\\]+)$/;
$filename=$1;
打印进度($percent,$u\u size,$bytes\u read,$filename);
}
}
子打印进度{
打开(PROG,“>”.$uploaded\u file\u progress);
打印程序“{”百分比“:”($\[0]*100)。“总计“$\[1]”,“上载“$\[2]”,“文件名“:”.$\[3].“}”;
关闭程序;
}
#############
$uphandle=$query->upload($query->param());
binmode$uphandle;
如果(!$error){
打开OUTFILE,“>”$上传的文件;
双模式输出文件;
而($bytesread=read$uphandle,$buffer,1024){
打印输出文件$buffer;
}
#while(){print OUTFILE$\u;}
关闭输出口;
}
如果脚本没有问题,我还需要检查哪些内容? 谢谢

编辑:日志中有:等待CGI脚本输出超时。
我怎样才能摆脱这个?我在谷歌上找不到明确的答案。

您可能需要将$CGI::POSTMAX设置为大于500MB的值,看看这是否能解决问题


如果我没有弄错的话,500MB是邮戳的默认值。我总是将我的设置为2GB(但是我用它来上传很多视频!)

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

我想您需要在Apache conf中插入Apache
TimeOut
配置变量

鉴于您正在使用perl,perlmonks.org上已经多次提到了这一点,并弹出了此链接作为回应


感谢您提供超时的指示。这是两台服务器上唯一不同的地方。我不敢相信事情竟那么简单。