2012-07-08 123 views
27

我正在研究什么是在PHP中设置默认值的最佳值。我见过很多与max_input_time有矛盾的观点。PHP文件上传是否受到max_input_time的影响?

这个回答说,他相信文件上传不向定时器计数: https://stackoverflow.com/a/3758522/518169

虽然PHP官方文档上,有一个巨大的红色警告说:

max_input_time sets the maximum time, in seconds, the script is allowed to receive input; this includes file uploads. For large or multiple files, or users on slower connections, the default of 60 seconds may be exceeded

来源:http://php.net/manual/en/features.file-upload.common-pitfalls.php,最后更新日期:2012年5月6日,星期五

因此,从这看起来max_input_time的确影响文件上传,并确保访问者可以上传20 MB的文件,即使是缓慢或移动连接,缺省值60肯定是不够的!

你有什么建议将此值设置为? 300?

此外,max_execution_timemax_input_time之间是否有任何关系?例如max_execution_time需要大于max_input_time

+0

我在上传大文件和Apache超时时遇到了一些问题,但是PHP没有。 – 2012-07-08 22:10:44

+0

有趣的是,我在我的一个托管服务提供商中遇到了相同的问题,尽管PHP配置中的所有内容都似乎合法,但较慢的连接上的大型上载导致了“HTTP/1.1 500内部服务器错误”。现在我已经看到第一个答案中的引号,我开始想知道真正的交易是什么。将密切关注这个主题,并尝试自己挖掘一些东西。 – brezanac 2012-07-09 13:50:30

回答

20

经过一些快速基准测试我不认为max_input_time对缓慢连接的用户处理大量上传有任何影响。

http://us3.php.net/manual/en/info.configuration.php#ini.max-input-time

This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. It is measured from the moment of receiving all data on the server to the start of script execution.

我使用PHP 5.3.8和使用下面的.htaccess配置

php_value max_input_time 5 
php_value max_execution_time 1 
php_value upload_max_filesize "2048M" 
php_value post_max_size "2048M" 

我的测试脚本是:

<?php 
if (!empty($_FILES)) { 
    echo '<pre>'; 
    var_dump($_FILES); 
    echo '</pre>'; 
} 
?> 
<form enctype="multipart/form-data" method="POST"> 
    File: <input name="userfile" type="file" /> 
    <input type="submit" value="Upload" /> 
</form> 

与几个试用我的1.5G文件大约需要月16日至17日秒上传4-5秒来处理,和执行时间基本上是0。

随着max_input_time 5脚本完成。随着它设置为4我们得到PHP Fatal error: Maximum execution time of 4 seconds exceeded in Unknown on line 0, referer: http://localhost/test-upload.php

它似乎也max_execution_time没有轴承,因为我们在整个测试保持在1。

+0

正是我在找的东西。谢谢! – 2013-03-15 21:01:58

+6

只想说,这个答案是不正确的。 在极少数情况下,缓慢的连接会让您损坏管道错误。 我刚刚修复了这个问题,它将max_input_time设置为600.现在我正在使用googling如何计算max_input_time,但只能看到不正确的答案。 – 2014-07-20 11:33:23

+0

@ BenP.P.Tung,这很重要。请添加更多详细信息。 – Pacerier 2015-03-25 14:37:38

5

这将取决于如何将PHP桥接到Web服务器。

从技术上讲,只要有请求头文件,web服务器就可以调用PHP--在这种情况下,PHP会扭曲它的大拇指,等待POST数据通过互联网,直到它可以填充请求变量(这很可能会超过max_input_time)。但更常见的情况是,网络服务器将延迟PHP的调用,直到它具有完整的请求(它不太可能会超出max_input_time)。

+2

谨慎提供有关此主题的进一步阅读?这是我第一次发现PHP处理在请求开始时被调用,从而影响'max_input_time'。谢谢。 – brezanac 2012-07-09 13:54:27

+0

@symcbean,**哪个**实现可以做到这一点?听起来不像是一种很好的分层应用程序的方式,因为PHP脚本现在需要打扰半路连接等情况。 – Pacerier 2015-02-02 12:51:21

+0

我可以证实这确实发生了。我在超过60秒的上传大文件时遇到了500错误。我只更改了max_input_time并修复了它。不仅如此,php手册现在有不同于上面引用的措辞。现在它说时间开始“在服务器调用PHP时”,而不是“从接收服务器上所有数据的时刻开始”。你可以在这里阅读:http://goo.gl/FTfsD3。奇怪的是PHP日志中的错误表示max_execution_time已经达到,即使我将它设置为10000。 – dallin 2016-01-14 17:01:23

7

我对max_input_time做了广泛的研究。网络传输时间不是一个因素。PHP作为Apache处理程序(mod_php)或Nginx/PHP-FPM -pair产生了类似的结果:一旦传输完成并且Web服务器将数据传递过来,PHP就获取上传的文件。在我的测试2秒max_input_time已足够处理800 MiB上传。

所有的细节都在http://blog.hqcodeshop.fi/archives/185-PHP-large-file-uploads.html

1

由于PHP 5.4,PHP文件上传绝对可以通过max_input_time设置影响。我最近在花费超过60秒的文件上传500错误。我在我的php.ini中改变了这个单值,它就消失了。

此外,手册中的措词与已接受的答案中引用的内容不同。它现在说:

This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins.

我使用的是PHP 5.4.16的nts和IIS 7.5。显然,在文件上传之前调用PHP。

一个有趣的事情要注意的是我的PHP错误日志给出了错误的错误。他们表示“PHP致命错误:超过10000秒的最大执行时间......”。无论我将max_execution_time设置为什么,它都会给新的编号带来同样的错误。

相关问题