php PHP文件上传是否受max_input_time影响?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11387113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:24:39  来源:igfitidea点击:

PHP file upload affected or not by max_input_time?

php

提问by hyperknot

I'm looking into what is the best value to set for defaults in PHP. I've seen many contradicting points about max_input_time.

我正在研究在 PHP 中设置默认值的最佳值是什么。我看到了很多关于max_input_time.

This answer says that he believes file uploading is not counted towards timers: https://stackoverflow.com/a/3758522/518169

这个答案说他认为文件上传不计入计时器:https: //stackoverflow.com/a/3758522/518169

While on the official PHP documentation, there is a huge red warning saying:

而在官方 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

max_input_time 设置允许脚本接收输入的最长时间,以秒为单位;这包括文件上传。对于大文件或多个文件,或连接速度较慢的用户,可能会超过默认值 60 秒

Source: http://php.net/manual/en/features.file-upload.common-pitfalls.php, last updated: Fri, 06 Jul 2012

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

So from this it seems to max_input_timedoes affectfile uploading and to be sure that visitors can upload say 20 MB files even from slow or mobile connections, the default value of 60 is definitely not enough!

因此,从这一点来看,它似乎max_input_time确实会影响文件上传,并且要确保访问者即使通过慢速或移动连接也可以上传 20 MB 的文件,默认值 60 绝对不够!

What do you recommend setting this value to? 300?

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

Also, is there any relationship between max_execution_timeand max_input_time? For example like that max_execution_timeneeds to be bigger than max_input_time?

另外,max_execution_time和之间有什么关系max_input_time吗?例如,这样max_execution_time需要大于max_input_time?

采纳答案by Dennis S Hennen

After some quick benchmarking I do not believe max_input_timehas any bearing on handling large uploads by users with slow connections.

经过一些快速基准测试后,我认为max_input_time这与处理连接速度较慢的用户的大量上传没有任何关系。

From http://us3.php.net/manual/en/info.configuration.php#ini.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.

这设置了允许脚本解析输入数据(如 POST 和 GET)的最长时间(以秒为单位)。它是从接收到服务器上所有数据的那一刻到脚本开始执行的时刻。

I'm using PHP 5.3.8 and used the following .htaccess config

我正在使用 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"

My test script is:

我的测试脚本是:

<?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>

With several trials my 1.5G file takes around 16-17 seconds to upload, 4-5 seconds to process, and execution time is essentially 0.

经过多次试验,我的 1.5G 文件上传大约需要16-17 秒,处理需要4-5 秒,执行时间基本上为 0。

With max_input_time 5the script completes. With it set to 4 we get PHP Fatal error: Maximum execution time of 4 seconds exceeded in Unknown on line 0, referer: http://localhost/test-upload.php

随着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

It also seems max_execution_timehas no bearing since we kept it at 1 throughout the tests.

它似乎max_execution_time也没有任何意义,因为我们在整个测试过程中都将其保持为 1。

回答by Jari Turkia

I did extensive study on max_input_time. Network transfer time is not a factor. PHP as Apache handler (mod_php) or Nginx/PHP-FPM -pair yielded similar results: PHP gets the uploaded file once the transfer is completed and web server hands the data over. On my tests 2 second max_input_timewas enough to handle a 800 MiB upload.

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

All the details are at http://blog.hqcodeshop.fi/archives/185-PHP-large-file-uploads.html

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

回答by symcbean

It's going to depend on how the PHP is bridged to the webserver.

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

Technically it's possible for the webserver to invoke PHP as soon as it has the request headers - in which case PHP is going to be twiddling it's thumbs waiting for the POST data to come across the internet until it can populate the request variables (it's quite possible that max_input_time will be exceeded). But more commonly, the webserver will delay the invocation of PHP until it has the the full request (it's a lot less likely that max_input_time wil be exceeded).

从技术上讲,网络服务器有可能在收到请求标头后立即调用 PHP - 在这种情况下,PHP 将摆弄它的拇指,等待 POST 数据通过互联网,直到它可以填充请求变量(这很有可能)将超过 max_input_time)。但更常见的是,网络服务器会延迟 PHP 的调用,直到它收到完整的请求(超过 max_input_time 的可能性要小得多)。

回答by dallin

As of PHP 5.4, PHP file uploads can definitely be affected by max_input_time. I recently was getting a 500 error on files that took longer than 60 seconds to upload. I changed this single value in my php.ini and it went away.

从 PHP 5.4 开始,PHP 文件上传肯定会受到 max_input_time 的影响。我最近在上传时间超过 60 秒的文件上收到 500 错误。我在我的 php.ini 中更改了这个单一的值,它就消失了。

In addition, the wording in the manual is different now from what is quoted in the accepted answer. It now says:

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

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 serverand ends when execution begins.

这设置了允许脚本解析输入数据(如 POST 和 GET)的最长时间(以秒为单位)。计时从在服务器调用 PHP 的那一刻开始并在执行开始时结束。

I was using PHP 5.4.16 nts and IIS 7.5. Apparently, PHP is invoked before the file is uploaded.

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

One interesting thing to note is my PHP error logs gave the wrong error. They stated "PHP Fatal error: Maximum execution time of 10000 seconds exceeded in...". It didn't matter what I set max_execution_time to, it would give the same error with the new number.

需要注意的一件有趣的事情是我的 PHP 错误日志给出了错误的错误。他们说“PHP 致命错误:最大执行时间超过 10000 秒……”。我将 max_execution_time 设置为什么并不重要,它会给出与新数字相同的错误。