Page 1 of 1

file delivery script (moved servers, now fails)

Posted: Sat Oct 03, 2009 2:10 am
by Phill64
Hi all,

I have been knocking my head against my desk for hours over this and then spent hours searching everywhere to find anything close to a solution. I have a simple file delivery script (snippet below) which worked fine on its original CentOS Apache server. now moved onto a Windows 2003 IIS server.. this script is not behaving.

What it should do... simply deliver the file. obviously.
What it does instead... delivers the file but it is a blank file... even if I add echo's to my script, nothing appears in the delivered file.. seriously, nothing, not even echo's

What it does (if I set it to deliver a smaller file)... delivers the file perfectly (and if i add echo's.. theyll appear in there too)

The file I need to deliver is about 22MB, please if someone knows what's going on tell me what I can be looking out for. It's not a permission problem I checked all that, and as I said I can deliver small files with it, but large files just come blank. .closest I found to this symptom online was someone whose IIS hangs on large files.. but mine does it.. it simply delivers nothing... what I truely don't understand is the act that echo's don't even come through in the delivered file, that makes no logical sense to me.

(some code snippets so u get what i mean by file delivery)

Code: Select all

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Pragma: no-cache");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache
 
// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".basename($filename).";");
 
readfile($filepath.$filename);
exit();

Re: file delivery script (moved servers, now fails)

Posted: Sat Oct 03, 2009 2:44 am
by Phill64
This gets even more messed up.

I've been desperately trying to work around this issue. the results are hard to believe.
I tried reading and outputting just a piece of the file. (first 2mb) and this worked. So i proceeded to make a for loop to deliver the file in pieces... well, if i set it to 2 or 3 mbs.. it wil ldleiver that much, (using firefox btw) the progress bar will appear and download the 3mb then stop n obviously be an invalid file (not the full 22).

So I set the loop to do all 22mb (in 1mb pieces btw) and the result? SAME AS BEFORE, a blank file! straight away! I was expecting that if it were to fail it woud download some pieces first, at last the first 3 as I'e seen it be able to do, then hang or cut short or something.. but it doesn't.. it simply delivers a blank file.. as per every other damn thing i've tried...

my weird loop deliver

Code: Select all

$fd = fopen($filepath.$filename, "r");
$tmb = 22;
for($mb = 0; $mb <= $tmb; $mb++) {
    echo fread ($fd, 1024*1024);
}
What is going on? I'm guessing IIS behaves very differently to the way most webservers do, and perhaps tyring t othroww everything in memory? that would be stupid but I wouldn't put it past microfail.. please any idea's someone?

P.S: Out of curiousity of how much this p.o.s will atcually deliver, I kept tuning the loop down, it would only work somewhere between 4mb-5mb... (tmb set to 4) that's it.. so any file over 5mb can't be delivered.. a devastating result.. and im guessing this is related to the servers page file being 4mb... this is extremely problematic for me...

Re: file delivery script (moved servers, now fails)

Posted: Sat Oct 03, 2009 5:19 am
by Phill64
Ok.. for now i've rewritten this delivery page in asp.net and it works fine.

However i'm not really pleased with this solution, so still welcome all suggestions on enabling php to deliver large files through IIS.. will be a pain to embed asp.net components into any future php sites that require this function...