---
title: PHPUnit runs out of memory
source: https://docs.newrelic.com/docs/apm/agents/php-agent/troubleshooting/phpunit-incompatibility
---

## Problem

When you use [PHPUnit](https://phpunit.de/) 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:

```ini
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](https://github.com/sebastianbergmann/phpunit/commit/0214cf81d8b12a1191932e6096d22c8496943911).
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!
