如题,假设PHP设置是默认的8M、2M,如果我同时向服务器发送大文件的话,会消耗大量服务器内存,甚至导致网站崩溃,这问题有解决办法吗?
下面这个是我做的测试代码,同时打开多个相同页面,然后在每个页面选择文件,等js触发自动提交表单
我本地测试,同时打开5个页面,选择的都是500M+的一个文件,当5个页面平均上传进度到50%左右的时候,页面崩溃了
test.html
<!DOCTYPE html>
<html>
<head>
<title>form</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="test.php">
<input type="file" name="file" >
<input type="submit" name="send" value="Submit">
</form>
<script>
var tt = new Date("2016-12-28 15:25:00").getTime();
var ct = null;
ct = new Date().getTime();
if(ct < tt){
loop();
}
function loop(){
setTimeout(function(){
ct = new Date().getTime();
console.log('new loop: ' + ct + ' -- ' + tt);
if(tt > ct){
loop();
}else{
console.log('go submitting');
document.forms[0].submit();
}
}, 1000);
}
</script>
</body>
</html>
test.php
<?php
$name = date("His") . mt_rand(1000,9999) . '.txt';
file_put_contents('./log/'.$name, var_export($_FILES, true));
?>
大概4分钟后: