Skip to content

Fix out-of-memory installs and surface Composer failure output - #61

Merged
joetannenbaum merged 2 commits into
2.xfrom
fix/in-process-composer-memory
Jul 23, 2026
Merged

Fix out-of-memory installs and surface Composer failure output#61
joetannenbaum merged 2 commits into
2.xfrom
fix/in-process-composer-memory

Conversation

@WendellAdriel

Copy link
Copy Markdown
Member

Overview

Installing large packages like rector/rector failed on machines with a finite php.ini memory_limit, reporting only Composer command failed: require rector/rector (or a misleading "Package not found" callout on older builds). The PHAR boots Composer in-process, which skips the bin/composer bootstrap that raises memory_limit to 1536M, so resolving rector + phpstan (needs more than 768M) died with a fatal OOM that cpx swallowed.

Solution

ComposerRunner::runInProcess() now mirrors the bin/composer bootstrap: it honors COMPOSER_MEMORY_LIMIT, raises finite limits below 1536M to 1536M, and leaves -1 or higher limits untouched. ComposerCommandException also appends Composer's captured output (ANSI-stripped and truncated) to its message, so the real diagnostic reaches both interactive and JSON output instead of an opaque one-liner.

Details

This explains the "works on my machine" reports: plain composer require rector/rector succeeds everywhere because bin/composer bumps its own memory limit, while cpx failed only for users with a finite memory_limit (the stock PHP default is 128M). Reproducible with PHPRC=<ini with memory_limit=512M> cpx rector/rector against a clean CPX_HOME, which now installs and runs Rector. The distributed PHAR is rebuilt with the fix.

Booting Composer in-process skips the bin/composer bootstrap, so the
user's php.ini memory_limit applied and large resolutions such as
rector/rector crashed with an OOM that cpx swallowed into a one-line
error. Mirror the bootstrap's memory bump (honoring
COMPOSER_MEMORY_LIMIT) and include Composer's captured output in
ComposerCommandException so failures are self-diagnosing.
@WendellAdriel
WendellAdriel marked this pull request as ready for review July 23, 2026 17:06
@WendellAdriel
WendellAdriel requested review from TitasGailius, Copilot and joetannenbaum and removed request for Copilot July 23, 2026 17:06
@joetannenbaum
joetannenbaum merged commit 7d2a1c1 into 2.x Jul 23, 2026
8 checks passed
@WendellAdriel
WendellAdriel deleted the fix/in-process-composer-memory branch July 24, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants