简体   繁体   English

PHP和Apache的随机缓慢下载速度

[英]Random Slow Download Speed with PHP & Apache

So my company store all PDF files in Amazon S3 privately. 因此,我公司将所有PDF文件私下存储在Amazon S3中。 When the user request it our system pull it from Amazon S3 and then serve it to the user with following code: 当用户请求时,我们的系统将其从Amazon S3中拉出,然后通过以下代码将其提供给用户:

header("Cache-Control: public");
header("Pragma: public");
header("Expires: 0");
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="'.$fileName.'"');
header('Content-Length: ' . strlen($res->body));
header("Content-type: application/pdf");
header("Content-Transfer-Encoding: binary");
header('Connection: close');
echo $res->body;

$res is the respond returned from Amazon with the content from $res->body; $ res是从Amazon返回的响应,其中包含$res->body;的内容$res->body;

I see random slow download speed when the user try to download the PDF files, especially when the PDF is large (~5mb) compare to the rest that only having 800kb-1.5mb. 当用户尝试下载PDF文件时,我看到随机的缓慢下载速度,尤其是在PDF较大(〜5mb)的情况下,与只有800kb-1.5mb的其他文件相比,下载速度特别慢。

Solution tried: 1) Removing the content-length header doesn't help. 尝试的解决方案:1)删除content-length标头没有帮助。 2) Remove EnableSendfile off in httpd.conf doesn't help either. 2)删除httpd.conf中的EnableSendfile也无济于事。

I also checked the server to make sure it wasn't the workload of the server that's causing this. 我还检查了服务器,以确保不是引起此问题的服务器工作量。 The speed test of both the server and user's workstation looks good too. 服务器和用户工作站的速度测试也都不错。

Do anyone of you have any idea what is the reason that's causing this slowness? 你们当中有人知道导致这种缓慢的原因是什么吗?

It might be that multiple people from your company use the internet. 您公司中可能有多个人使用互联网。 You should do a full scan of the network, but still even then your not alone on the internet, and their "virtual" server environments are shared as well. 您应该对网络进行全面扫描,但即使如此,您也不能孤单地在Internet上,并且它们的“虚拟”服务器环境也可以共享。

from my understanding the issue is that simply takes time to fetch the file from S3 in order to return it to the user. 从我的理解来看,问题在于,只需花费一些时间从S3中获取文件,然后将其返回给用户即可。

Make yourself a favor: 帮个忙:

  1. create a signed url for a short period time 在短时间内创建一个签名的URL
  2. redirect the user to such url 将用户重定向到该网址

dont worry, as creating signed urls doesn't expose any private information that compromises your security (if you do ir correctly) 不用担心,因为创建签名的URL不会暴露任何会危害您安全性的私人信息(如果您没有正确操作的话)

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

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