2

我在我的服务器上设置了一个带有 PHP 的下载脚本,它在让用户通过 Apache (X-Sendfile) 下载文件之前检查一些细节。文件位于 Document-Root 之外。

使用 Apache 和 Module X-Sendfile 下载的代码是:

header("X-Sendfile: $fullpath");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$link_file\"");

使用 Apache 和 X-Sendfile 时,我的客户端下载速度为500 kB/s。我还使用 Apache 和没有 X-Sendfile 的文档根目录中的相同文件对其进行了测试 - 这里也是一样!

所以我测试了下载相同的文件,使用相同的客户端,双方相同的基础设施和相同的互联网连接几秒钟后通过 PHP 和 readfile:

header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Length: ".(string)(filesize($fullpath)));
header("Content-Disposition: attachment; filename=\"$link_file\"");
readfile($fullpath);

这次下载速度是9.500 kB/s

我多次使用这两个选项重复此测试,每次尝试的结果都是相同的。尝试使用 PHP readfile 方法时,除了下载速度之外,唯一的区别是等待时间为几秒钟(取决于下载的文件的大小)。当立即重复 PHP readfile 方法时,等待时间没有再次出现。很可能是因为它在第一次之后存储在内存中。

我在服务器上使用了一个专业的 HP Raid-System,它的平均本地速度为 800 MB/s,所以原因不能是 Diskspeed。我也没有在 Apache 的 httpd.conf 中找到任何压缩或带宽设置。

你们中的任何人都可以解释为什么下载速度有如此大的差异以及如何改变这种差异?

先感谢您。

  • 服务器:Windows Server 2008 R2 Apache/2.2.21 (Win32) PHP/5.4.20
  • 客户端:Windows 7 Ultimate x64 Google Chrome 30.0.1599.101 LAN >100 Mbit/s
4

1 回答 1

6

解决方案:

httpd.conf,打开“EnableSendfile off”行

于 2013-10-27T00:25:19.200 回答