Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File handle causes caching

Status
Not open for further replies.

Tyger

Programmer
Sep 19, 2001
21
GB
I have written the following simple script to control delivery of a file to a user's browser through Perl. When loading this up the user will be prompted with a "Save as..." dialog box and once they have selected a destination the file will be downloaded to their computer.

#!/usr/bin/perl

print "content-disposition: attachment; filename=\"big.bin\"\n";
print "content-type: application/octet-stream\n\n";

binmode(STDOUT);
open (DOWN, &quot;< C:/bigfile/200m.bin&quot;);
binmode(DOWN);
print <DOWN>;
close DOWN;

This works fine for small files, even up to 10 or 20 MB but when I tested it with a 200MB file there is a vast amount of hard disk activity before either the webserver times out or the server machine crashes.

This makes me suspect that the file is being cached by the server and it appears to occur when the script is first accessed (the &quot;Save as&quot; dialog does not appear).

I am not sure if this is an OS, webserver or Perl issue but I have tried it in the following configurations with the same outcome:

Windows 2000+Xitami Webserver (Localhost)
Windows 2000+Apache 2.0 (Localhost)
Windows XP+Apache 1.3 (Via LAN)
RedHat Linux 8+Apache 2.0 (Localhost, Via LAN and Via web)

I have scoured the web for information about webserver caching and all evidence suggests that this is disabled by default. I have also tried a modified version of this program which reads and writes 1 byte of data at a time but this makes no difference.

Thanks.
Tyger.
 
Something you may want to try, though I'm not sure it's the problem. Whenever I access files with binmode set, I use sysread and syswrite. Could you use that to read a certain chunk size, then send it out, then read the next chunk, and so on?

Also, do you have to set STDOUT to binary mode as well? ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top