• /
  • EnglishEspaรฑolFranรงaisๆ—ฅๆœฌ่ชžํ•œ๊ตญ์–ดPortuguรชs
  • Log inStart now

PHPUnit runs out of memory

Problem

When you use PHPUnit version 11 or newer to manage and run your unit tests, and have New Relic PHP agent installed and enabled, executing the phpunit script (the PHPUnit command-line test runner) will cause it to consume all available system memory before actually running any tests.

Solution

To prevent out-of-memory errors you must explicitly disable the agent by setting newrelic.enabled to false. You can disable it while using phpunit like this:

bash
$
php -d newrelic.enabled=false vendor/bin/phpunit tests/

For example, to run a specific test file:

bash
$
php -d newrelic.enabled=false vendor/bin/phpunit tests/Unit/ExampleTest.php

Important

This workaround disables all New Relic instrumentation while running unit tests, meaning no APM data will be collected during test execution.

Alternatively, you can disable the agent in your php.ini configuration file if you need this setting permanently for your development environment:

newrelic.enabled = false

Cause

The reason for this incompatibility is new code that was added in PHPUnit 11.x: Reapply "Check and restore error/exception global handlers" ยท sebastianbergmann/phpunit@0214cf8. This new code retrieves the list of active exception handlers using a method that requires popping each exception handler off the exception handler stack. However, the New Relic PHP Agent installs its own exception handler by default and prevents it from being removed from the exception handler stack. The agent detects when its exception handler is being removed and immediately re-registers it. This causes an infinite loop in the phpunit script: PHPUnit can never finish popping handlers off the stack because the New Relic PHP Agent continuously re-registers its handler!

Copyright ยฉ 2025 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.