135

How to increase transaction timeout? I want to upload videos, but large size of videos not uploaded?

It throws error The process *** exceeded the timeout of 60 seconds.

9
  • 1
    Define "transaction timeout". What doesn't work where?
    – Pekka
    Sep 30, 2010 at 9:40
  • 1
    why do you think its "transaction" timeout? Sep 30, 2010 at 9:41
  • short videos uploaded successfully. but long video not uploaded, i think time out.
    – Amir
    Sep 30, 2010 at 9:42
  • ini_set('post_max_size','200M'); ini_set('upload_max_filesize','200M'); ini_set('max_execution_time','200M'); ini_set('max_input_time','200M'); ini_set('memory_limit','200M'); set_time_limit(65536);
    – Amir
    Sep 30, 2010 at 10:38
  • 1
    it is better to split the file before upload it. There are many apps that can be used. I preffer plupload.
    – bksi
    May 27, 2014 at 18:29

14 Answers 14

167

You need to change some settings in your php.ini:

upload_max_filesize = 2M 
;or whatever size you want

max_execution_time = 60
; also, higher if you must - sets the maximum time in seconds

Where your PHP.ini is located depends on your system environment. For more information: http://php.net/manual/en/ini.list.php

12
  • sorry, I've no clue what you mean by that :(
    – Hannes
    Sep 30, 2010 at 9:50
  • @Aamir, You need to have permission from your webhost to change in the configruation of your web server. Often, they wont let you change stuff like that.
    – hellozimi
    Sep 30, 2010 at 9:50
  • can i change upload_max_filesize and max_execution_time in htaccess file?
    – Amir
    Sep 30, 2010 at 9:55
  • 2
    @Col , I disagree, he wants to make the changes on the fly and not over the whole application, so he asks how he can do that. And even if he were to ask how he can just change some stuff in the php.ini it may be a newbie question, but an legit question all the same.
    – Hannes
    Sep 30, 2010 at 10:13
  • 1
    @IulianOnofrei alright, just feeld the need to point that out :D, but maybe if you don't know what it is its still good to look it up … "Those who cannot learn from history are doomed to repeat it" and all that …
    – Hannes
    Jul 17, 2014 at 7:15
73

You should be able to do during runtime too using

set_time_limit(100);

http://php.net/manual/en/function.set-time-limit.php

or in your vhost-config

php_admin_value max_execution_time 10000

Having a global execution time limit that is LOW is mostly a good idea for performance-reasons on not-so-reliable applications. So you might want to only allow those scripts to run longer that absolutely have to.

p.s.: Dont forget about post_max_size and upload_max_filesize (like the first answer told allready)

1
  • If you set it then sleep will be ignored
    – Snake Eyes
    Jan 30, 2018 at 10:23
25

To complete the answer of Hannes.

You need to change some setting in your php.ini:

upload_max_filesize = 2M 
;or whatever size you want

max_execution_time = 60
; also, higher if you must

If someone want put in unlimited (I don't know why but if you want), you can set the time to 0:

You need to change some setting in your php.ini:

upload_max_filesize = 0 

max_execution_time = 0

And if you don't know where is your php.ini. You can do a file "name.php" in your server and put:

<?php phpinfo(); ?>

And on your website, you can see the config of your php.ini and it's marked where is it.

Edit on 9 January 2015:

If you can't access your php.ini, you have two more options.

You can set this line directly in your "name.php" file but I don't find for upload_max_filesize for this option:

set_time_limit(0);

Or in ".htaccess"

php_value upload_max_filesize 0
php_value max_execution_time 0
17

if what you need to do is specific only for 1 or 2 pages i suggest to use set_time_limit so it did not affect the whole application.

set_time_limit(some_values);

but ofcourse these 2 values (post_max_size & upload_max_filesize) are subject to investigate.

you either can set it via ini_set function

ini_set('post_max_size','20M');
ini_set('upload_max_filesize','2M');

or directly in php.ini file like response above by Hannes, or even set it iin .htaccess like below

php_value upload_max_filesize 2M
php_value post_max_size 20M
8

If you happen to be using Microsoft IIS server, in addition to the php.ini settings mentioned by others, you may need to increase the execution timeout settings for the PHP FastCGI application in the IIS Server Manager:

Step 1) Open the IIS Server Manager (usually under Server Manager in the Start Menu, then Tools / Internet Information Services (IIS) Manager).

Step 2) Click on the main connection (not specific to any particular domain).

Step 3) Under the IIS section, find FastCGI Settings (shown below).

enter image description here

Step 4) Therein, right-click the PHP application and select Edit....

Step 5) Check the timeouts (shown below).

enter image description here

In my case, the default timeouts here were 70 and 90 seconds; the former of which was causing a 500 Internal Server Error on PHP scripts that took longer than 70 seconds.

5

As an addition to above answers, you may use set_time_limit() function:

http://php.net/manual/en/function.set-time-limit.php

passing 0 as an argument will make your script run with no time limit.

2
  • 1
    set_time_limit() has nothing to do with file uploads Sep 30, 2010 at 10:08
  • 1
    This is not accurate enough Col. Shrapnel. While on Unix environments the max-execution time is compared to the cumulative CPU-time used by the php-thread, on windows systems the absolute time is used. Uploading is mostly "idle-time" (IO-Wait). But as you see uploads can stop when it takes too long even though. Sep 30, 2010 at 10:21
4

If you cannot edit php.ini (on your server for example) you can attempt to change the php.ini parameters from within your php code. Try:

ini_set('max_execution_time', 'NUMBER OF SECONDS TO ALLOW BEFORE TIMEOUT');

If that doesn't work, try also setting 'set_time_limit' in the same way, beyond that I'd say your only option is to contact your host. These settings cannot be modified while in safe mode.

1
  • 3
    Hannes got this a minute before I posted, and correctly points out that set_time_limit() should not be set by ini_set, as stated in this answer but by putting the seconds in the brackets. Voted hannes up.
    – John
    Sep 30, 2010 at 10:06
3

I know you are specifically asking about the PHP timeout, but what no one else seems to have mentioned is that there can also be a timeout on the webserver and it can look very similar to the PHP timeout.

So if you have tried:

  1. Increasing the timeout in php.ini by adding a line: max_execution_time = {number of seconds i.e. 60 for one minute}
  2. Increasing the timeout in your script itself by adding: ini_set('max_execution_time','{number of seconds i.e. 60 for one minute}');

And you have checked with the phpinfo() function that max_execution_time has indeed be increased, then you might want to try adding this to .htaccess which will make sure Apache itself does not time out:

RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]

More info here: https://www.antropy.co.uk/blog/php-script-keeps-timing-out-despite-ini-set/

3

First check the php.ini file path by phpinfo(); and then changed PHP.INI params:

upload_max_filesize = 1000M
memory_limit = 1500M
post_max_size = 1500M
max_execution_time = 30

restarted Apache

set_time_limit(0); // safe_mode is off

ini_set('max_execution_time', 500); //500 seconds

Note: you can also use command to find php.ini in Linux

locate `php.ini`
3

You had a typo: ini_set('max_input_time','200M') - value set needs to be an int, like ini_set('max_input_time','200')

2

Test if you are is safe mode - if not - set the time limit (Local Value) to what you want:

if(!ini_get('safe_mode')){

    echo "safe mode off";
    set_time_limit(180);// seconds

    phpinfo();// see 'max_execution_time'
}

*You cannot set time limit this way if safe mode 'on'.

1

optional : if you set config about php.ini but still can't upload

-this is php function to check error code

$error_type = [];
$error_type[0] = "There is no error";
$error_type[1] = "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
$error_type[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
$error_type[3] = "The uploaded file was only partially uploaded.";
$error_type[4] = "No file was uploaded.";
//$error_type["5"] = "";
$error_type[6] = "Missing a temporary folder. Introduced in PHP 5.0.3.";
$error_type[7] = "Failed to write file to disk. Introduced in PHP 5.1.0.";
$error_type[8] = "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.";
//------------------------------
//--> show msg error.
$status_code = $_FILES["uploadfile"]["error"];
if($status_code != 0){
    echo $error_type[$status_code];
    exit;
}
0

You can also set a max execution time in your .htaccess file:

php_value max_execution_time 180
0

To really increase the time limit i prefer to first get the current value. set_time_limit is not always increasing the time limit. If the current value (e.g. from php.ini or formerly set) is higher than the value used in current call of set_time_limit, it will decrease the time limit!

So what's with a small helper like this?

/**
 * @param int $seconds Time in seconds
 * @return bool
 */
function increase_time_limit(int $seconds): bool
{
    return set_time_limit(max(
        ini_get('max_execution_time'), $seconds
    ));
}

// somewhere else in your code
increase_time_limit(180);

See also: Get max_execution_time in PHP script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.