Why is set_time_limit(0) bad? 🤔

Nick Anthony
1 min readMay 16, 2019

--

In PHP you have the option to use a function called “set_time_limit()”. The purpose of this function is to set your PHP script execution time to a certain set period of time. The default is normally 30 seconds, but check your php.ini file to find out the default.

Some developers set this to 0 which means the script execution time will not have a time limit imposed.

Why is this bad?
Setting your time limit to 0 is bad because you don’t have full control over your script and scenarios like this can occur:

  • Your script connects to a remote service, the time spent in the connection will not be controllable by a set time limit;
  • Your script will be using memory and process power to run this process which can slow down other users visiting;

What should you do?
There’s no right or wrong answer, you need to evaluate the use case for your application.

What you should do if you have an application that executes scripts with a high execution time:

  • Look into queue workers, this will give you the option to queue that process work so your application can continue to perform as it should;

--

--