Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpunit memory_limit parameter does not apply

Tags:

I've just installed phpunit via pear in a mac osx 10.7 and everything works fine except I got memory limit errors (xdebug enabled for reports).

I tried to add the -d memory_limit=512M parameter to phpunit but it is not applying because, on the very first error, I added var_dump(ini_get('memory_limit')); exit; and it prints string(3) "32M"

So, why is it not being applied?

Besides that, if I run

php -d memory_limit=256M -r "echo ini_get('memory_limit');" 

it echoes "256M"

Is it possible that phpunit is not executing same php?

like image 501
jerkan Avatar asked Jan 10 '12 20:01

jerkan


People also ask

What is the maximum memory_limit value can be set for PHP by default?

The default memory limit is 256M and this is usually more than sufficient for most needs. If you need to raise this limit, you must create a phprc file.

What is memory_limit in PHP INI?

The PHP memory_limit is the maximum amount of server memory that each PHP script is allowed to consume. Per the PHP documentation: “This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts from eating up all available memory on a server.”

How set PHP memory limit in Linux?

To increase the PHP memory limit setting, edit your PHP. ini file. Increase the default value (example: Maximum amount of memory a script may consume = 128MB) of the PHP memory limit line in php. ini.


1 Answers

Yes you can set every php option with phpunit -d that can be set with ini_set.

You already opened a bug over in the phpunit bug tracker but well I'm going for the more verbose answer here

Reproduce to show it works in general:

echo "<?php var_dump(ini_get('memory_limit')); " > foo.php  phpunit -d memory_limit=12M --bootstrap foo.php  

Produces:

string(3) "12M" PHPUnit 3.6.5 by Sebastian Bergmann. 

But phpunit only applies this option once before the first test is run!

So chances are your code is somewhere changing the memory limit back to 32M which is something phpunit can't "fix".

Same goes for setting the memory limit in the phpunit.xml file.

like image 66
edorian Avatar answered Sep 30 '22 03:09

edorian