2

I tried increasing the value of max_execution_time in php using

ini_set('max_execution_time', 108000);

which equals to 30 hours. I was just playing with this value to crawl websites with large amount of data in it. But, I go this fatal error that said the maximum execution time cannot exceed 30 seconds. When I changed 108000 value to 300, my script executed for 5 minutes. I wonder what is the maximum allowed value for this thing in php?

Kilvish Shakal
  • 129
  • 2
  • 4
  • 13
  • i would suggest you to use php through CLI. It is not affected by `max_execution_time` and will work until it's finished. – Inurosen Sep 11 '15 at 14:16
  • I dont want to execute some script. Just wanted to know the maximum allowed value. I browsed the documentation but they didn't state it there. – Kilvish Shakal Sep 11 '15 at 14:22
  • 2
    0 should remove the time limit altogether and let your script run forever (if it wants). is that the answer you're looking for? – Jeff Lambert Sep 11 '15 at 14:28
  • possible duplicate of [max\_execution time limit php](http://stackoverflow.com/questions/26938773/max-execution-time-limit-php) – Jeff Lambert Sep 11 '15 at 14:29
  • No, It's Not Duplicate. He Is Asking The Maximum Value For Maximum_Exection_Time. – Nana Partykar Sep 11 '15 at 14:31

2 Answers2

4

Correct answer in reference to Mjh's comment.

Signature for parsing integer ini values:

ZEND_API long zend_ini_long(char *name, uint name_length, int orig);

Therefore the maximum value that can be entered into that field is: 2147483647

Old answer.

The only clue I could find was here: https://github.com/php/php-src/blob/master/main/php_ini.h

#define php_ini_long    zend_ini_long

Which eventually leads back to: https://github.com/php/php-src/blob/master/Zend/zend_long.h

typedef int64_t zend_long;

That is a 64 bit integer, or:

−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

EDIT: Correction.

// PHP x64
typedef int64_t zend_long;

// PHP x86
typedef int32_t zend_long;

So the max value is PHP_INT_MAX.

If you are getting errors saying it cannot exceed 30 seconds, this is because your server configuration has forbidden changing that value to anything above 30 seconds.

Flosculus
  • 6,880
  • 3
  • 18
  • 42
  • 1
    Since I was doing the same thing as you, I stumbled upon `INI_INT` macro, which turns out to be a wrapper for [zend_ini_long](http://lxr.php.net/xref/PHP_5_6/Zend/zend_ini.c#348) which calls [strtol](http://man7.org/linux/man-pages/man3/strtol.3.html), which returns the long integer. Having dumped this wall of text in the comment, have my upvote, your answer is correct if my crawling through the code has been correct :) – Mjh Sep 11 '15 at 15:10
  • @Mjh Does that mean it only returns a `long`, since it doesn't use `strtoll` for the 64 bit systems? – Flosculus Sep 11 '15 at 15:17
  • It appears so, it returns `long` always, unless I missed something obvious while browsing [lxr.php.net](http://lxr.php.net). – Mjh Sep 11 '15 at 15:20
  • Then my answer is only half right. If you post the correct one you can have a one up from me :P – Flosculus Sep 11 '15 at 15:21
  • I believe you can edit yours and include stuff from my comment, IMO it's better not to post too many "correct" answers :) – Mjh Sep 11 '15 at 15:22
  • But when I changed this manually to 2147483647 in php.ini file, I still got the same fatal error. However, placing the code ini_set('max_execution_time', 2147483647); in a random php test file actually worked. Why did that happen? – Kilvish Shakal Sep 11 '15 at 16:23
  • I don't think `ini_set('max_execution_time', 2147483647);` is actually setting it to that value. I did a similar test earlier with a 128 bit figure and it didn't complain. This is limitation imposed by the web server. See answer by @Alex. – Flosculus Sep 11 '15 at 16:31
1

Quoting the manual set_time_limit

seconds The maximum execution time, in seconds. If set to zero, no time limit is imposed.

It maybe unlimited so perhaps for php the limit is just the maximum int value.

But there could be external factors, if I remember correctly suhosin patch have its own maximum execution time if executed from a web server maybe the server itself have some limit, looking at php sources I've the impression also network timeouts may be a factor.

Alex
  • 3,264
  • 1
  • 25
  • 40
  • +1 for mentioning external factors. apache has a timeout directive and iis has a timeout function, both of which can pre-empt the setting of `max_execution_time` – Jeff Lambert Sep 11 '15 at 15:12