Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get max_execution_time in PHP script

Tags:

php

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?

like image 767
T. Zengerink Avatar asked Dec 19 '11 13:12

T. Zengerink


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 .

How can I limit time in PHP?

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.

How do you calculate max execution time?

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.


2 Answers

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.

like image 122
Jon Avatar answered Sep 18 '22 09:09

Jon


There are some inaccurate points in the comments. So to clarify:

  1. set_time_limit(30) is the same as ini_set('max_execution_time', 30);
  2. Both of them reset the counter.
  3. ini_get('max_execution_time') works for both cases - set_time_limit and ini_set.
like image 39
David Avatar answered Sep 18 '22 09:09

David