简体   繁体   English

通过Apache下载的速度比使用PHP readfile的下载速度慢

[英]Slower downloads through Apache than with PHP readfile

I've set up a Download-Script with PHP on my server, which checks some details before letting the user download files via Apache (X-Sendfile). 我已经在服务器上使用PHP设置了一个下载脚本,该脚本会在允许用户通过Apache下载文件(X-Sendfile)之前检查一些详细信息。 The Files are outside the Document-Root. 文件不在文档根目录下。

The code for downloading with Apache and the Module X-Sendfile is: 使用Apache和X-Sendfile模块下载的代码是:

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

When using Apache and X-Sendfile i have a download-speed of 500 kB/s with my client. 使用Apache和X-Sendfile时,我的客户端的下载速度为500 kB / s I also tested it with Apache and without X-Sendfile with the same file within the Document Root - same thing here! 我还使用Apache对其进行了测试,而没有X-Sendfile,并且在文档根目录中使用了相同的文件-这里也是一样!

So I tested downloading the same file, with the same client, the same infrastructure on both sides and the same internet-connection a few seconds later via PHP with readfile: 因此,我测试了几秒钟后通过带有readfile的PHP通过相同的客户端,相同的两侧基础结构以及相同的Internet连接下载相同的文件:

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);

This time the download-speed was 9.500 kB/s ! 这次下载速度为9.500 kB / s

I repeated this test using both options more than a multiple times and the result was the same every time trying. 我多次使用这两个选项重复了此测试,每次尝试的结果都是相同的。 The only difference besides the download-speed was a waiting time of a few seconds (depending on the size of the file which was downloaded), when trying with the PHP readfile method. 尝试使用PHP readfile方法时,除了下载速度之外,唯一的区别是等待时间为几秒钟(取决于下载文件的大小)。 When repeating the PHP readfile method instantly, the waiting time didn't appear again. 立即重复PHP readfile方法时,等待时间不再出现。 Most likely because it was stored in the memory after the first time. 最有可能是因为它是第一次存储在内存中。

I'm using a professional HP Raid-System on the server, which has an average local Speed of 800 MB/s, so the reason for this can't be the Diskspeed. 我在服务器上使用专业的HP Raid系统,该计算机的平均本地速度为800 MB / s,因此无法使用Diskspeed。 Also i didn't find any compressing- or bandwith-settings in the httpd.conf of Apache. 我也没有在Apache的httpd.conf中找到任何压缩或带宽设置。

Can anyone of you explain why there is such a great difference of the download-speed and how this can be changed? 谁能解释为什么下载速度有如此大的差异,以及如何更改?

Thank you in advance. 先感谢您。

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

SOLUTION: 解:

httpd.conf, turn on the line "EnableSendfile off" httpd.conf,打开“ EnableSendfile off”行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM