PHP 大文件上传内存问题
我最近接管了一个文件托管网站(类似于rapidshare、megaupload 等),目前平均每天约有 75,000 名访客。迁移之后,我们从头开始编写自己的系统。现在是时候升级基础设施了,并且一直在研究网络服务器和扩展。现在的问题是,文件上传完成后,Web 服务器没有“刷新”用完的内存。我们上传了多个300MB+的文件,上传之前,我们有大约3.7G的可用内存,上传3个每个300M的文件后,内存使用量约为1.2G。最初,我们认为这可能是 apache 问题,但升级到 Litespeed 也没有解决它。这是来自“top”
Mem的“内存使用情况”:总共4015996k,已用1206036k,空闲2809960k,114984k缓冲区
我正在绞尽脑汁想弄清楚如何“刷新”Web服务器或php在上传过程中使用的内存,因为这样系统很快就会耗尽内存并崩溃。
这是我的 php.ini 值:
max_execution_time = 6000 最大输入时间 = 6000 内存限制 = 2048M post_max_size = 2047M upload_max_filesize = 2047M
在 Apache 上,php 在 fcgi 上运行,在 Litespeed 上运行,它是 Litespeed SAPI。
谢谢, 账单
I recently took over a file hosting site (similar to rapidshare, megaupload etc.) and currently averaging about 75k visitors/day. After the migration, we wrote our own system from scratch. It's now time to upgrade the infrastructure and have been toying around with web servers and scaling. Now the issue is that after file upload is complete, the web server is not "flushing" the used-up memory. We uploaded multiple 300MB+ files and before the upload, we had about 3.7G of memory free and after uploading 3 files of 300M each, the memory usage stands at around 1.2G. Initially, we thought it could be apache issue, but upgrading to Litespeed didn't fix it either. Here's the "memory usage" from 'top'
Mem: 4015996k total, 1206036k used, 2809960k free, 114984k buffers
I am scratching my head to figure out how to "flush" the memory used up by the web server or by php during the upload, because this way the system will run out of memory and crash in no time.
Here are my php.ini values:
max_execution_time = 6000
max_input_time = 6000
memory_limit = 2048M
post_max_size = 2047M
upload_max_filesize = 2047M
On Apache, php runs on fcgi and on Litespeed, it's Litespeed SAPI.
Thanks,
Bill
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚发现它是“缓存内存”,我可以通过以下命令释放它:
回声3> /proc/sys/vm/drop_caches 内存
总计:4015996 kB
内存空闲:2490780 kB
缓冲区:118232 kB
缓存:1204168 kB
交换缓存:0 kB
活跃:358748 kB
不活动:991220 kB
活跃(匿名):28024 kB
不活动(匿名):0 kB
活动(文件):330724 kB
非活动(文件):991220 kB
不可驱逐:0 kB
锁定:0 kB
高总计:3179664 kB
高免费:1918528 kB
低总计:836332 kB
低免费:572252 kB
交换总计:48827384 kB
无隔夜利息:48827384 kB
I just figured out that it is the "cache memory" and I am able to free it up by this command:
echo 3 > /proc/sys/vm/drop_caches
MemTotal: 4015996 kB
MemFree: 2490780 kB
Buffers: 118232 kB
Cached: 1204168 kB
SwapCached: 0 kB
Active: 358748 kB
Inactive: 991220 kB
Active(anon): 28024 kB
Inactive(anon): 0 kB
Active(file): 330724 kB
Inactive(file): 991220 kB
Unevictable: 0 kB
Mlocked: 0 kB
HighTotal: 3179664 kB
HighFree: 1918528 kB
LowTotal: 836332 kB
LowFree: 572252 kB
SwapTotal: 48827384 kB
SwapFree: 48827384 kB