通过Apache下载慢比PHP的ReadFile [英] Slower downloads through Apache than with PHP readfile

查看:735
本文介绍了通过Apache下载慢比PHP的ReadFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了下载脚本用PHP我的服务器,它通过Apache(X-SENDFILE)让用户下载文件之前检查一些细节上。该文件在文档根目录之外。

在code与Apache和模块下载的X SENDFILE是:

 标题(X-SENDFILE:$完整路径);
标题(内容类型:应用程序/八位字节流);
标题(内容处置:附件;文件名= \\$ link_file \\);

在使用Apache和X-SENDFILE我有 500 KB / S 的下载速度和我的客户端。我公司还与Apache和不带X-SENDFILE与文档根在同一文件内测试了 - !在这里同样的事情

所以我测试下载同一个文件,具有相同的客户端,两侧相同的基础架构和相同的互联网连接,几秒钟后通过PHP与ReadFile的:

 标题(杂注:无缓存);
标题(缓存控制:必重新验证,检查后= 0,pre-检查= 0);
标题(内容类型:应用程序/八位字节流);
标题(内容长度:(串)(文件大小($完整路径)));
标题(内容处置:附件;文件名= \\$ link_file \\);
ReadFile的($完整路径);

这一次的下载速度为 9.500 KB / S

我重复使用这两种选择多于一个多次该试验中,结果为每一次相同的尝试。除了下载速度,唯一的区别是在几秒钟(取决于其下载的文件的大小),用PHP ReadFile的方法试图当一个等待时间。当瞬间重复PHP ReadFile的方法,等待的时间也没有再次出现。最有可能的,因为它被存储在所述存储器中的第一时间之后

我使用的服务器,它拥有800 MB /秒的平均本地速度对专业的HP的Raid-系统,所以这样做的原因不可能是Diskspeed。我还没有发现任何COM pressing-或在Apache中的httpd.conf的带宽设置。

能否有人对你解释为什么是下载速度的这么大的差异,这可怎么改变?

感谢您提前。


  

      
  • 服务器:Windows Server 2008 R2中的Apache / 2.2.21(的Win32)PHP / 5.4.20

  •   
  • 客户端:Windows 7旗舰版64位谷歌浏览器30.0.1599.101 LAN> 100 Mbit / s的

  •   


解决方案

解决方案:

httpd.conf文件,打开就行了EnableSendfile关

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). The Files are outside the Document-Root.

The code for downloading with Apache and the Module X-Sendfile is:

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. I also tested it with Apache and without X-Sendfile with the same file within the Document Root - same thing here!

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:

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!

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. When repeating the PHP readfile method instantly, the waiting time didn't appear again. 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. Also i didn't find any compressing- or bandwith-settings in the httpd.conf of Apache.

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
  • Client: Windows 7 Ultimate x64 Google Chrome 30.0.1599.101 LAN >100 Mbit/s

解决方案

SOLUTION:

httpd.conf, turn on the line "EnableSendfile off"

这篇关于通过Apache下载慢比PHP的ReadFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆