I know it is possible to set the maximum execution time in a script using either:
ini_set('max_execution_time', 30);
or
set_time_limit(30);
What can I do to get a variable containing the maximum execution time in seconds?
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 .
Use PHP inbuilt function set_time_limit(seconds) where seconds is the argument passed which is the time limit in seconds. It is used, when the user changes the setting outside the php. ini file. The function is called within your own PHP code.
You can control the amount of time PHP allows scripts to run by changing the max_execution_time directive in your php. ini file. To verify the current value of the max_execution_time directive and other directives, you can use the phpinfo() function.
The converse, using ini_get
:
ini_get('max_execution_time');
Note: if you check the documentation page for ini_set
, you can find ini_get
listed prominently on the "See Also" section. That's a very good way to discover functionality built into PHP that you are not already aware of.
There are some inaccurate points in the comments. So to clarify:
set_time_limit(30)
is the same as ini_set('max_execution_time', 30);
ini_get('max_execution_time')
works for both cases - set_time_limit
and ini_set
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With