A PHP application is offering binary data as a download:
header("Content-Type: application/octet-stream");
header("Pragma: public");
header("Cache-Control: private");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("expires: 0");
set_time_limit(0);
ob_clean();
flush();
@readfile($completefilename); exit;
$completefilename is a stream like “ftp://user:pwd@…”
The size of the data can be several MByte. It works fine, but sporadically I get the following error:

It’s most likely that the remote stream is occasionally down, or times out.
Also as @fab says it could be that the file you are trying to load is larger than your script’s memory.
You should start logging the errors
readfile()returns, e.g. using theerror_logphp.ini directive.If this needs to be completely foolproof, I think you’ll have to use something more refined than
readfile()that allows to set a timeout (likecurl, orreadfilewith stream context options).You could then catch any errors that occur while downloading, and serve a locally hosted fallback document instead. That document could e.g. be a text file containing the message “Resource xyz could not be loaded”.