Skip to content
Latchkey

Composer "Allowed memory size of X bytes exhausted" in CI

Composer's dependency solver is memory-hungry and hit PHP's memory_limit. Composer runs the CLI with no limit by default, but a low memory_limit in the CI PHP config can still cap it. Set COMPOSER_MEMORY_LIMIT=-1 to remove the cap for Composer only.

What this error means

composer install or update dies with "PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate ...)" partway through solving.

PHP
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted
  (tried to allocate 20480 bytes) in phar:///usr/bin/composer/.../Solver.php

Common causes

A restrictive memory_limit in the CI PHP

The runner PHP sets a low memory_limit that Composer inherits, and a large graph exhausts it during resolution.

A large or complex dependency graph

Solving many packages with wide ranges allocates a lot of memory, exceeding the configured limit.

How to fix it

Raise the Composer memory limit

  1. Set COMPOSER_MEMORY_LIMIT=-1 for the composer step so PHP uses unlimited memory.
  2. Re-run the install.
  3. Prefer this over editing global php.ini so only Composer is affected.
.github/workflows/ci.yml
- run: composer install --no-interaction
  env:
    COMPOSER_MEMORY_LIMIT: -1

Install from the lock without re-solving

Committing composer.lock and running composer install (not update) skips the heaviest solving work.

Terminal
composer install --no-interaction --prefer-dist

How to prevent it

  • Set COMPOSER_MEMORY_LIMIT=-1 for composer steps in CI.
  • Commit composer.lock so CI installs rather than re-solves.
  • Avoid running composer update on every CI job.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →