🔥 How to Bypass Composer's Memory Issue

Published on June 3rd, 2020.

Since I reset my laptop a few months back I've been getting memory errors when I try and run Composer commands, like composer update.

Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.%

But today, I've finally found a proper solution to bypass them whenever you run into them.

Instead of running just composer update, you can run this instead: php -d memory_limit=-1 /usr/local/bin/composer.

That command will temporally set your local PHP's memory limit to -1 (so basically unlimited) and will use the normal composer binary to run the rest of the command.

Hopefully someone finds this helpful.

My picture

Duncan McClean