How to increase PHP's file execution time

Introduction

If you're uploading a file, and the transfer ends prematurely, your PHP script is probably reaching its maximum execution time limit before the upload has finished. Provided your web host allows it, this article explains 3 methods to increase the limit.

Prerequisites

In Monsta FTP's config file

Open the file /mftp/settings/config.php and change the following variable to the number of seconds to increase the limit to.

$configMaxExecutionTimeSeconds = 1800;

In your server's PHP.INI file

You, or your server administrator, need to adjust the variable max_execution_time in your server's PHP.INI file.

The default number is normally 30, measured in seconds, and you can specify whatever time you wish.

After changing PHP.INI you may need to restart your web server.

In an .htaccess file

Add the following lines to your .htaccess file, setting 30 to your preferred number of seconds.

<IfModule mod_php5.c>
php_value max_execution_time 30
</IfModule>

Other Solutions

Are you running Fast CGI?

If you're running Fast CGI you may be getting this error in your logs:

HTTP request length n (so far) exceeds MaxRequestLen (n)

Open your Apache vhost configuration and add the FcgidMaxRequestLen directive with a big enough value (in bytes), for example:

FcgidMaxRequestLen 200000000 (which equals roughly 200 MB)

Finally, restart Apache.

Did you run out of disk space?

If the above solution doesn't work for you, you might want to check your server's available disk space.

Copy the following PHP to a new file on your server and run through your browser. This will tell you how much free space you have.