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 h
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_time was enough to handle a 800 MiB upload.
All the details are at http://blog.hqcodeshop.fi/archives/185-PHP-large-file-uploads.html
It's going to depend on how the PHP is bridged to the webserver.
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).
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.
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 server and ends when execution begins.
I was using PHP 5.4.16 nts and IIS 7.5. Apparently, PHP is invoked before the file is uploaded.
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.
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.