Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP file upload affected or not by max_input_time?

Tags:

php

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?

like image 463
hyperknot Avatar asked Jul 08 '12 22:07

hyperknot


People also ask

What is the maximum file upload size in PHP?

The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.

How can I upload large files over 500mb in PHP?

By changing the upload_max_filesize limit in the php. ini file. By implementing file chunk upload, that splits the upload into smaller pieces an assembling these pieces when the upload is completed.

How does PHP file upload work?

A PHP script can be used with a HTML form to allow users to upload files to the server. Initially files are uploaded into a temporary directory and then relocated to a target destination by a PHP script. The user opens the page containing a HTML form featuring a text files, a browse button and a submit button.


1 Answers

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.

like image 118
Dennis S Hennen Avatar answered Sep 20 '22 04:09

Dennis S Hennen