Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On using ini_set('max_execution_time', 0);

How do I use ini_set('max_execution_time', 0);?

Question 1: Do I place it at the top of the .PHP file or in a function that takes a long time to do something?

Question 2: Does this setting last forever after being set? Or does it return back to its original 300sec or whatever default value after the function stops running?

like image 559
Nyxynyx Avatar asked Jun 29 '11 15:06

Nyxynyx


People also ask

What is max_execution_time in PHP?

max_execution_time int. This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30 . When running PHP from the command line the default setting is 0 .

What does set_time_limit 0 mean?

Syntax: set_time_limit ( int $seconds ) Return Value: Boolean ( True or False ) Default value:30 seconds. For the maximum or you can say for the infinite execution time, we can set the function with the 0 value. If the value is 0 then it will run for an infinite time.


1 Answers

You can place it anywhere, but that setting won't take effect until it runs. So if you put it at the top, then the script will never timeout. If you put it down below on the function that can take awhile, then you may get a timeout above if the script takes a long time to get to where you called it.

When you use ini_set() that option stays in effect for the entire execution of the script.

like image 198
Brad Avatar answered Sep 28 '22 02:09

Brad