IIS上的PHP问题


PHP issue on IIS, maybe

V1rtualset

我真的不确定这个问题属于哪个领域,但我最接近的选择是php配置。问题是,我有一个来自SumEffect的电子商务平台,名为Digistop,它是基于php的。允许客户下载产品的下载功能导致了一个错误,这意味着我的客户无法获得他们的产品。SumEffect的支持者已经洗手不干了,说问题是我的。在不就我是否适合运行服务器提出抗议的情况下,有人可以看看这段代码和错误消息,并对我可能尝试修复的问题进行深入的猜测吗?

服务器2008 R2IIS 7.5PhP 5.3.6

这是代码

$path = 'C:/Documents/Virtualsetworks/files/VSPHD1080S164.zip';
$downloadFile = basename($path);
$filesize = filesize($path);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $downloadFile . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
if($filesize){
    header('Content-Length: ' . $filesize);
}
header('Content-Encoding: chunked'); //This is passed so in case the default encoding of the server uses compression a progress bar will display.

$handle = fopen($path, 'rb');
$chunksize = 1024;
$length = 0;
ob_start();
while($line = fread($handle, $chunksize)){
    echo $line;
    ob_end_flush();
    ob_flush();
    flush();
    ob_start();
}
fclose($handle);
ob_end_clean();

?>

以下是客户端的错误:"F:''E''temp''VSPHD1080S164(13(.zip无法保存,因为无法读取源文件。请稍后再试,或与服务器管理员联系。">

我的客户也明白这一点,不仅仅是我。

它通常读取9到10兆字节的文件,然后停止,等待一段时间,然后抛出该消息。有时它读取0个字节,或者只有几个字节,但大多数情况下它会达到9.3MB。PHP.ini memory_limit是1024Mb,最大执行时间是1200。文件夹具有所有正确的安全权限。有问题的文件在100-1000Mb之间。zlib.output_compression=关闭max_execution_time=1200最大输入时间=60memory_limit=1024MIIS 7.5 Windows 2008 R2

如有任何帮助,将不胜感激

为什么在"转储文件内容"部分重复启动/停止输出缓冲?这是对cpu周期的可怕浪费。只需:

// open the file first thing, so the die() can be seen, if something fails
$handle = fopen($file, 'rb') or die("Unable to open $file");
// THEN output the download headers    
header(...);
header(...);
// simple while loop, no need for any buffering/flushing.    
while(!feof($handle)) {
    echo fread($handle, $chunksize);
}

此外,您的"内容编码"标头也不正确。对于分块下载,您可以使用Transfer-encoding。由于您发送的是整个文件,因此不需要分块编码——无论如何,您都没有进行正确的分块。对于分块传输,您必须在发送时为每个分块输出一个内容长度。