PHPUnit Maximum Execution Time

When I look at the PHP configuration, it says max_execution_time = 0, however, my PHPUnit script times out after 120 seconds. My php.ini file indicates it should be 700 seconds (for development machines.)

I can't seem to alter this. I've tried adding max_execution_time=0 to the PHPUnit config, but no luck.

6 comments
Comment actions Permalink

Well, if you are executing "normal" PHPUnit (which is in CLI mode) and not "PHPUnit on Server" one, then max_execution_time = 0 by default.

If you want to check the php.ini value, then execute this simple script in CLI mode and find that setting:

<?php phpinfo(INFO_CONFIGURATION); ?>


If you use this one, you will see which php.ini file was used exactly:

<?php phpinfo(INFO_GENERAL); ?>

Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => E:\Projects\php\php.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)


Also, by using PHP Interpreters management (Settings | PHP), you can override any configuration variable with your custom value (Advanced | Configuration Options).

Even PHPUnit run configuration has "Command Line | Interpreter options" field. Example:

-d max_execution_time=30000

http://www.php.net/manual/en/features.commandline.options.php


If you see only 120 seconds -- maybe it's PHPUnit itself? Maybe it has some default time limit for single test execution? I really doubt -- will just quote their ooold ticket: "Not a PHPUnit issue. Besides, you should be able to use phpunit -d max_execution_time=0 ... to achieve what you want."

But please check your phpunit.xml (or whatever config file you may be using) -- maybe you have <php> ... </php> section, where you can override php.ini settings: http://www.phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.php-ini-constants-variables

0
Comment actions Permalink

<?php phpinfo(INFO_CONFIGURATION); ?>

Ok, this is showing me max_execution_time of 120. However, I use set_time_limit(300) just about that call (top of the bootstrap.php file.) My php.ini file is set to 700. I've tried using

phpunit -d max_execution_time=0


Has no effect. It seems like nothing I do changes the time limit from 120.

And no, nothing in the phpunit.xml file.
0
Comment actions Permalink

OK.Few more things to check:

1) If you search your php.ini for max_execution_time -- what do you find? 700?

2) When executing phpinfo() (with no params or with INFO_GENERAL), do you see Additional .ini files parsed => (none) or there are some extra files parsed?

3) Back to php.ini -- if you search for auto_prepend_file -- what do you find?

4) When executing phpinfo(), how does the line with max_execution_time looks exactly? Like this: max_execution_time => 120 => 120 or a bit different?

0
Comment actions Permalink

From my php.ini file:

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 700


When executing phpinfo(), it displays Additional .ini files parsed => (none)

Again from my php.ini

; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file =


Hmm, the phpinfo() actually looks like this:

max_execution_time => 120 => 0


What does that mean?

The thing is, this works fine with XDebug - meaning, I can pause the script for 10 minutes and it won't timeout. However, with PHPUnit, it's behaving differently.

0
Comment actions Permalink
What does that mean?

As far as I'm aware (after checking comment in php.ini for that setting as well after reading some articles on internet), this setting has NO effect for CLI mode, as it is hardcoded to 0.

The format is:

Directive => Local Value => Master Value


So .. AFAIK it has to be some script that set the time limit (as if that value is passed as a parameter to php.exe, it will look differently -- see below). In any case, you should be able to override that value with set_time_limit() -- at least it does work here.


Let me clarify this moment: as I understand you've added call to phpinfo() into your bootstrap.php file that is executed with PHPUnit tests and you checking these values by executing your tests and checking generated output. Is that correct?

If so -- have you tried execuing that directive as separate file (e.g. info.php) ? Do you see different results?

What about executing it directly from command line -- will the value be different?

php.exe -f info.php


For example, when excuting this one:

php.exe -d max_execution_time=333 -f info.php

the result should be:

max_execution_time => 333 => 333


If you put set_time_limit(1234); before call to phpinfo(), with the above command line the result should be

max_execution_time => 1234 => 333

---

Considering that "this works fine with XDebug" .. I can only suggest checking your code (whole project including all libraries) -- please scan for set_time_limit(). That's what I would do as from overhere I can't think of any other places.

0
Comment actions Permalink

Keith,

Do you still have the issue?

You can override 'max_execution_time' option in PHP interpreter configuration:
max_execution_time.png

Examinate your configuration using 'Show phpinfo' action:
phpinfo.png

Thank you for feedback!

0

Please sign in to leave a comment.