2019-04-10 00:19
浏览 207

Apache 2.4 + PHP 7.2 prefork mpm +文件上传导致20秒后部分上传错误

I've been noticing an issue with a web application we have where our application's code that handles file uploads would intermittently encounter file upload error 3. I wasn't sure how our users were triggering this error but I do know that the ones who did would be uploading files through an unstable or slow internet connection (mobile hotspots, public wifi, etc). So I tested this by using Chrome Dev Tools' throttling feature (fast 3g) and uploading a 10mb file that would take somewhere around a minute or more to complete. We use the Dropzonejs library to handle uploads by the way with no chunking whatsoever. After exactly 22 - 23 seconds, the connection always seems to get aborted but Apache still proceeds to handle the incomplete request body it receives and passes it to PHP, leading to a partial upload error.

I can't seem to figure out what is causing this to happen. PHP config has max_execution_time and max_input_time set to 0 and -1 respectively. Post and upload max sizes are set relatively high and well, the file upload size doesn't even seem to matter. As long as the upload request takes longer than 22 - 23 seconds, the problem occurs. I tried disabling mod_reqtimeout and it didn't make a difference. Other things I've tried are tinkering with the apache Timeout value and disabling keepalive and it still gives me issues a little after 20 seconds always (that time comes from the browser's network tab).

I don't see anything in apache's error logs and the access logs make these requests appear legit, since apache still continues to handle the incomplete request like normal.

I initially thought it might be dropzonejs killing the ajax request connection but I have also tested the same code on my local dev environment which uses laradock (software versions will be slightly different. Still both apache 2.4 and php 7.2) and I cannot replicate the issue, so it couldn't be a client-side problem.

图片转代码服务由CSDN问答提供 功能建议

我一直注意到我们的Web应用程序存在问题,处理文件上传的应用程序代码会间歇性地遇到 文件上传错误3.我不确定我们的用户是如何触发此错误但我知道那些人会通过不稳定或慢速的互联网连接(移动热点,公共wifi等)上传文件。 因此,我通过使用Chrome Dev Tools的限制功能(快速3g)并上传一个大约需要一分钟或更长时间才能完成的10mb文件进行测试。 我们使用Dropzonejs库来处理上传,无需任何分块。 在22到23秒之后,连接似乎总是中止,但Apache仍然继续处理它收到的不完整的请求主体并将其传递给PHP,导致部分上传错误。

我似乎无法弄清楚导致这种情况发生的原因。 PHP配置的max_execution_time和max_input_time分别设置为0和-1。 发布和上传最大大小设置得相对较高,文件上传大小甚至看起来都不重要。 只要上传请求的时间超过22 - 23秒,就会出现问题。 我试过禁用mod_reqtimeout并没有什么区别。 我尝试过的其他事情是修补apache Timeout值并禁用keepalive,它仍然会在20秒之后给我一些问题(该时间来自浏览器的网络选项卡)。


我最初认为它可能是dropzonejs 杀死ajax请求连接,但我也测试了我的本地开发环境中使用laradock的相同代码(软件版本会略有不同。仍然是apache 2.4和php 7.2)我无法复制问题,所以它不可能 客户端问题。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanduan1993 2019-04-10 18:33

    Looks like it was mod_reqtimeout stopping my post requests. I think my apache changes just weren't propagating fully when I initially tried disabling it (I'm guessing due to a mix of me using a graceful restart and having keepalive enabled).

    解决 无用
    打赏 举报
  • dongpobo6009 2019-04-29 16:22

    We had the same issue and solved thanks to this question. However there is no need to entirely disable the module. The problem is caused by this bug in Apache 2.4.39:

    As suggested in the bug report you can explicitly set the default in Apache config file.

    解决 无用
    打赏 举报

相关推荐 更多相似问题