Composer "Allowed memory size of X bytes exhausted" in CI
Composer's dependency solver is memory-hungry on large graphs. When it exceeds PHP's memory_limit, the CLI dies with a fatal memory error. Composer is meant to run without a memory cap, set via COMPOSER_MEMORY_LIMIT.
What this error means
composer update or install aborts with "PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate ...)" inside a Composer source file.
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
(tried to allocate 20480 bytes) in
phar:///usr/local/bin/composer/src/Composer/DependencyResolver/...Common causes
A restrictive php.ini memory_limit
The runner PHP caps memory_limit (often 128M) and the solver needs more for a large dependency graph.
A heavy update over many packages
A full composer update builds a large solve state; on a big project it can outgrow the default cap.
How to fix it
Remove the limit for the Composer process
Set COMPOSER_MEMORY_LIMIT to -1 so Composer runs without a PHP memory cap.
env:
COMPOSER_MEMORY_LIMIT: '-1'Or raise it inline for one command
Override memory_limit just for the Composer call without changing global php.ini.
php -d memory_limit=-1 /usr/local/bin/composer updateHow to prevent it
- Set
COMPOSER_MEMORY_LIMIT=-1in CI for install and update steps. - Prefer
composer installfrom a lock so the solver does little work. - Scope
composer update <pkg>to specific packages instead of the whole graph.