Re: Timeout while waiting for a server->client transfer to start (large files)

From: Date: Thu, 31 Jan 2008 00:02:55 +0000
Subject: Re: Timeout while waiting for a server->client transfer to start (large files)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-268382@lists.php.net to get a copy of this message
On Tue, January 29, 2008 12:45 pm, Barney Tramble wrote: > I have a script that I am trying to figure out to allow a remote file > to > be sent to a client's browser. It works ok for small files, but it > keeps > timing out for large files. I don't think it should even take as long > as > it does (i.e. about 10seconds) before it pops up a dialog box for me > to > download a 700KB file. Any ideas? It times out on a line around which > reads > > while (!feof($fp)) > { > $tmp .= fread($fp, 64); > } Your script is reading the whole file, 64 measly bytes at a time, into a monstrous string $tmp. Then, finally, when you've loaded the whole [bleep] file into RAM in $tmp, you just echo it out, right? Don't do that. :-) while (!feof($fp)){ echo fread($fp, 2048); } You can play around with 2048 versus 64 versus 1000000 on your box to see what's "fastest" but I'll be pretty shocked if 64 bytes is the best performer... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So?

« previous php.general (#268382) next »