整理电脑资料时,看到了n年前的资料,发出来凑个数,更新一下博客。
E**M中下载大文件碰到的问题大文件下载时apache 容易出现内存分配不够问题,因为下载时需要把文件内容用php读取出来,放在缓冲区中,如果输出和刷新内存缓冲的间隔控制不好的话,可能会引发内存分配不够,且下载速度相对比较慢的情形,目前的做法是在apache中限制每个进程最多的线程数和请求数以降低内存消耗,同时经过测试得到了一个经验值,就是每次读取50k内容到缓冲区,下载完之后刷新内存缓冲。例子程序如下:
while(!feof($fp))
{
echo fread($fp, 51200);
flush();
ob_flush();
}
fclose($fp);
ob_end_flush();
apache的主要配置参数如下:
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 128
MaxRequestsPerChild 1
</IfModule>
<IfModule worker.c>
StartServers 2
MaxClients 128
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 2
</IfModule>
<IfModule perchild.c>
NumServers 5
StartThreads 5
MinSpareThreads 5
MaxSpareThreads 10
MaxThreadsPerChild 20
MaxRequestsPerChild 2
</IfModule>
<IfModule mpm_winnt.c>
ThreadsPerChild 250
MaxRequestsPerChild 2
</IfModule>
<IfModule beos.c>
StartThreads 10
MaxClients 128
MaxRequestsPerThread 2
</IfModule>
<IfModule mpm_netware.c>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 256
MaxRequestsPerChild 16
MaxMemFree 100
</IfModule>
<IfModule mpmt_os2.c>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 16
</IfModule>