Question

For some reason, our webserver is not responding while it's serving large files. We use the windows platform, because we need to remotely call Win32 applications in order to generate the file that is to be served. This file is served through PHP's function: fpassthru, using this code:

if (file_exists($file)) {

$handle = @fopen($file, "rb");
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
if($stream==0){
    header('Content-Disposition: attachment; filename='.basename($filename.".mp4"));
}

header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));

ob_end_clean();

fpassthru($handle);

exit;

}

These files are often over 1GB in size and takes a while to transfer, but during this time, the webserver will not serve any pages. My firefox indicates it's 'connecting' but nothing else. Note that somebody else is transferring this file, not me, so different IP, different session.

Any clue where to look? Obviously, it's intolerable to have to wait 5 minutes for a website. Thanks in advance!

Was it helpful?

Solution

This is commonly caused when you do not close the session before you begin sending the file data. This is because the session cache file can only be opened by one PHP process at a time, therefore the download is effectively blocking all other PHP processes at session_start().

The solution is to call session_write_close() to commit the session data to disk and close the file handle before you start outputting the file data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top