Timing: Monday - Friday 10:00am to 6:00pm

Increase PHP script execution time

With a default install of PHP the scripts have a limited

Increase PHP script execution time

With a default install of PHP the scripts have a limited execution time in which they much execute, do their thing, and finish. Quite often particularly in shared hosting environment the default limit just isn’t enough. This is quite often the case if you’re trying to upload large files or process a lot of data at once.

If you haven’t already seen it you will be greeted with the following error message if your PHP script reaches the execution time limit.

Fatal error: Maximum execution time of 60 seconds exceeded in /location/of/php/script.php on line 101

The solution to this problem is usually quite a simple one as PHP lets you increase the maximum script execution time quite easily. There are two ways of doing it, the first of which involves editing the php.ini configuration file. To change the PHP script execution time using the php.ini file simply open it up, do a search for max_execution_time and increase whatever the value is set to. The number used should be in seconds.

If however you don’t have access to the php.ini file (most shared hosting companies do not allow this) then you’re still in with a chance. It’s possible to change PHP maximum execution time inside your scripts and it’s very easy to do.


The above code snippet will set the PHP maximum execution time to be 120 seconds which should be plenty of time for most scripts. This line of code should be put at the very beginning of your PHP scripts making sure that nothing has been sent to the browser before your script has reached this line (otherwise it won’t work).

Alternatively if you don’t have a specific time limit in mind it is possible to tell your server to run your scripts endlessly with the following.


Setting the seconds value to be zero means your script has no execution time limit and will therefore just keep going. Try to avoid this if possible though: sometimes it’s good for there to be limits in place as it stops your scripts from using up too many system resources.

Like(0) un-like(0)

Leave a Reply