大文件传输期间未提供网页(IIS7.5 + PHP)

时间:2014-01-17 21:28:45

标签: php iis-7.5 file-transfer large-files

出于某种原因,我们的网络服务器在提供大型文件时没有响应。 我们使用Windows平台,因为我们需要远程调用Win32应用程序以生成要提供的文件。该文件通过PHP的函数提供:fpassthru,使用以下代码:

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;

}

这些文件的大小通常超过1GB,需要一段时间才能传输,但在此期间,网络服务器不会提供任何页面。我的Firefox表明它正在“连接”,但没有别的。请注意,其他人正在传输此文件,而不是我,因此不同的IP,不同的会话。

任何线索在哪里看?显然,对于一个网站来说,等待5分钟是不能容忍的。 提前谢谢!

1 个答案:

答案 0 :(得分:1)

这通常是在开始发送文件数据之前未关闭会话时引起的。这是因为会话缓存文件一次只能由一个PHP进程打开,因此下载有效地阻止session_start()处的所有其他PHP进程。

解决方法是在开始输出文件数据之前调用session_write_close()将会话数据提交到磁盘并关闭文件句柄。