php的输出是有限的
我这里有一个问题,也许以前有人已经经历过这个问题。
系统控制器提供 php 下载服务,它从文件中读取信息并将下载内容发送给客户端。系统运行完美。问题是速度总是很低,对于用户来说总是低于300kb/s,乘以低于100kb/s。
服务器有一个100mbps的链接6mbps免费并且客户有,那么应该以600kb/s的速度下载。有东西保存着 php 的输出。我尝试在 apache 的缓冲区中搜索,但没有发现任何关于这个问题的信息。
有谁知道会发生什么?
I have a problem here, maybe someone has already gone through this before.
A system controller is serving php downloads, it reads information from files and sends the client as a download. The system works perfectly. The problem is that speed is always low, always less than the 300kb/se times less than 100kb / s for the user.
The server has a 100mbps link 6mbps free and the customer has, then it should be downloaded at 600kb / s. Something is holding the output of php. I've tried searching on the buffers of apache but found nothing on this issue.
Does anyone have any idea what might be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PHP 确实不是为处理大文件而构建的。它必须将整个文件读入内存,然后输出。听起来你正在通过 PHP 发送合理的流量,如果每个用户 100kb/s - 300kb/s 太慢,通过诸如 readfile() 之类的东西这是一个坏主意。相反,我建议查看
mod_xsendfile
(如果您使用的是 Apache)或您选择的 Web 服务器的等效项(例如,我更喜欢 nginx,并且会使用XSendFile
为了这)。在 PHP 中,您可以这样做:
header('X-Sendfile: ' . $file);
。服务器拦截标头并发送该文件。它可以让您享受到使用 PHP 所做的事情的好处,以及 Web 服务器直接读取文件的速度。PHP really isn't built for processing large files. It has to read that entire file into memory and then output it. It sounds like you're sending a reasonable amount of traffic through PHP, if 100kb/s - 300kb/s per user is too slow, via something like
readfile()
which is a bad idea. Instead, I suggest taking a look atmod_xsendfile
(if you're using Apache) or it's equivalent for your web server of choice (e.g. I prefer nginx, and would useXSendFile
for this).In PHP then, you can just do this:
header('X-Sendfile: ' . $file);
. The server intercepts the header, and sends that file. It allows you the benefits of what you're doing with PHP, and the speed of the web server directly reading the file.