PHP文件上传是否受max_input_time影响? [英] PHP file upload affected or not by max_input_time?

查看:101
本文介绍了PHP文件上传是否受max_input_time影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究为PHP中的默认值设置的最佳值是什么.我已经看到关于max_input_time的许多矛盾之处.

此答案表明他认为文件上载不计入计时器: https://stackoverflow.com/a/3758522/518169

在官方的PHP文档中,有一个巨大的红色警告说:

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

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

因此,看来max_input_time 确实会影响文件的上传,并确保访问者即使在速度较慢或移动连接的情况下也可以上传说20 MB的文件,因此默认值60绝对不是足够的!

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

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

解决方案

在进行了快速基准测试后,我认为max_input_time对处理连接缓慢的用户的大量上载没有任何影响.

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

这设置允许脚本解析输入数据(如POST和GET)的最长时间(以秒为单位). 从接收服务器上所有数据的时间到脚本执行开始的时间进行测量.

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

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.

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

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

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

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

So from this it seems to max_input_time does affect file 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!

What do you recommend setting this value to? 300?

Also, is there any relationship between max_execution_time and max_input_time? For example like that max_execution_time needs to be bigger than max_input_time?

解决方案

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

From 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.

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

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.

With max_input_time 5 the 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

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

这篇关于PHP文件上传是否受max_input_time影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆