sbhalgat has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I am downloading large file(file size more than1.9GB)
I am using Perl, Mason.
When I click to file to download, browser(Firefox) hangs.
I am not able to find what is the exact problem.
Tried to flush the buffer using $m->flush_buffer.but didn’t help.
Can you please help me to find out why it is not working?

Please find the below code which I written
my $file = "$file_name"; if (-e $file) { local *FH; open FH, $file or die "Unable to open file"; if (-B $file){ binmode FH; } $r->content_type('application/octet-stream'); $r->set_content_length(-s FH); $r->headers_out->add("Content-Disposition" => qq(attachment; filename= +"$display_filename")); my $buffer; $m->autoflush(1); while (sysread(FH, $buffer, 262144)) { $m->out($buffer); } $m->autoflush(0); close FH; return;

Replies are listed 'Best First'.
Re: Getting problem while downloading large file(1.9GB)
by CountZero (Bishop) on Jan 16, 2012 at 06:49 UTC
    What does the error-log of the server say?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Error log on server says

      Out of memory!
      Callback called exit.

        Well, that settles it then.

        You now have two options:

        1. Get more memory in the server; or
        2. Re-write your application so you do not need to have the wholehave less of the file in memory at the same time.
        Update: edited the above to make it more clear.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Getting problem while downloading large file(1.9GB)
by Anonymous Monk on Jan 16, 2012 at 07:01 UTC
Re: Getting problem while downloading large file(1.9GB)
by pvaldes (Chaplain) on Jan 16, 2012 at 14:25 UTC
    You can try with wget and see if you have the same problem