≡ Menu

How to increase PHP max_execution_time?

Question – I have a PHP script that runs for about 15 minutes. It processes a lot of data and outputs a summary. But after a few seconds, PHP says that max_execution_time was exceeded and it aborts the script. How do I increase the max_execution_time so that my script would complete its processing?

The PHP variable max_execution_time is the maximum time a PHP script can run. The default value is 30 seconds which should be enough for most web applications. The execution time starts when PHP has completed the interpretation of the script and ends when the last statement has executed. The tasks that an operating system and the PHP interpreter has to do are not counted in the execution time. External commands run using system or exec do not count towards the execution time. When PHP is called from the command line, the max_execution_time is unlimited.

If a script runs for more than the max_execution_time, PHP will return a timeout error and terminate the script.

As you mentioned in the question, there are cases in which the default max_execution_time of 30 seconds is not enough. You may need to increase this to a value suitable for your web application.

How to change the value of max_execution_time?

First, you need to find out what max_execution_time is set on your PHP installation:

Locate your php.ini file and check what the value of the max_execution_time directive is:

[root@server ~]# php -i | grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
[root@server ~]# grep -i max_execution /etc/php.ini
max_execution_time = 30
[root@server ~]#

So, on my server, the max_execution_time is 30 seconds.

Open your php.ini in your favorite editor:

vi /etc/php.ini

Then change the value of the variable max_execution_time to whatever you desire. For example, a maximum execution time of 15 minutes, change the variable to 900 seconds:

max_execution_time = 900

How to make the max_execution_time to unlimited?

A value of 0 will make the max execution time to unlimited. However, it is not recommended that you do this. In cases in which a script has somehow gone into an infinite loop, or is in a deadlock because of file level locking, your server will get overloaded and your memory and CPU usage will go above recommended thresholds.

To make the maximum execution time to unlimited, change the value of the variable to the following:


Choose the value of this variable very carefully to avoid unnecessary server load!

How to set max_execution_time per PHP script?

PHP has a function called set_time_limit which can be called to override the value of the max_execution_time variable in php.ini. For example, to change the execution time limit for just one PHP script to 15 minutes, add the following line at the beginning of the PHP script:


This will override the settings in php.ini for that particular script only.

Incoming search terms:

  • how to raise max_execution_time in webmatrix (49)
  • max_execution_time (34)
  • php max_execution_time (14)
  • how to make unlimited max_execution_time in php ini (1)
  • php set max_execution_time (1)
  • what is max_execution_time 0 (1)

{ 0 comments… add one }

Leave a Comment