Am I right to assume that my first code attempt took forever since I had to load the file into memory first. And my second attempt is faster since I send the headers first then start sending data when I read the first line?
Yes.
Is there a better way to do this?
Is this a binary file? (application/* implies it is.) If so, you should set binmode on the output handle (after sending the header) and on the input handle.
Again, if this is a binary file, you should probably set $/ to a block size. You're reading a line at a time, and there's no guarantee to be any line feeds in your file, so you could theoretically end up reading the whole file at once the second way too. For example, $/ = \1024; Refer to the documentation of $/ in perlvar for details.
In reply to Re: Improving a File Download Script
by ikegami
in thread Improving a File Download Script
by awohld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |