Page 1 of 1

Serving file downloads through PHP

Posted: Mon Mar 10, 2008 7:04 pm
by EoN
Hi all,

I'm getting a really weird problem, and I don't know a) where the problem actually lies. b) how to determine where the problem lies. c) how to fix it.

I have a website, that basically serves links to download files. Similar in architecture to 'yousendit.com' (but quite different really). Basically a file is created, and php links are given to various people to download the file which identifies the person.

The problem is, although MOST of the downloads for a file will work fine, occasionally every now & then downloads will just 'STOP' downloading in mid-download. It's intermittent, and if the user clicks download again, most often the whole thing will download. I have no idea what's causing it, but I'm desperate to solve it. My first thoughts are that it might be network problems on my shared web hosting environment. Is that possible? Here is the code I'm using to serve the file:

Code: Select all

header('HTTP/1.1 200 OK');
header('Date: ' . date("D M j G:i:s T Y"));
header('Last-Modified: ' . date("D M j G:i:s T Y"));
header("Content-Type: application/octet-stream");
header("Content-Length: " . (string)(filesize($fileHandle)) );
header("Content-Transfer-Encoding: Binary");
header('Content-Disposition: attachment; filename="'.$fileName.'"' );
readfile($fileHandle);
Can anyone think of why these downloads might just 'stop' all of a sudden? Is there any better way of serving files through PHP? Is it less reliable to serve files through php than directly through the file system?

Any help would be greatly appreciated as I've been stuck on this one for a whle!

Thanks,
EoN

Re: Serving file downloads through PHP

Posted: Mon Mar 10, 2008 9:11 pm
by Sekka
The files may be bigger than the allowed memory consumption in your php.ini?

This post may help you.

viewtopic.php?f=1&t=79656