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

Diagnose it: platform requirements and auth

Composer resolves against the PHP version and extensions actually present, so a lockfile that installs locally can be unsatisfiable on a runner with a different PHP build.

Terminal
php -v && php -m | head -30
composer diagnose
composer check-platform-reqs

# install exactly what is locked, non-interactively
composer install --no-interaction --prefer-dist --no-progress

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.

Frequently asked questions

What causes Composer "Allowed memory size of X bytes exhausted" in CI?
There are 2 common causes: a restrictive memory_limit in the ci php and a large or complex dependency graph. The runner PHP sets a low memory_limit that Composer inherits, and a large graph exhausts it during resolution.
How do I fix Composer "Allowed memory size of X bytes exhausted" in CI?
There are 2 fixes depending on which cause you have: raise the composer memory limit and install from the lock without re-solving. Work through them in order, since the first is the most common.
What does Composer "Allowed memory size of X bytes exhausted" in CI actually mean?
composer install or update dies with "PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate ...)" partway through solving.
How do I stop Composer "Allowed memory size of X bytes exhausted" in CI happening again?
Set COMPOSER_MEMORY_LIMIT=-1 for composer steps in CI. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

This is an out-of-memory kill, not an application error. Latchkey detects, repairs, and retries it for you. Start free → 30-day trial · No credit card