Blog
Published on

Composer - PHP Fatal error: Allowed memory size

Authors

If you've been using composer you might have stumbled upon this frustrating error.

$ 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 67108864 bytes) in phar:///usr/local/Cellar/composer/1.10.6/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.% 

I've had it a few times recently and found the solution that works best.

COMPOSER_MEMORY_LIMIT=-1 composer update

By setting the global COMPOSER_MEMORY_LIMIT to -1 we're allowing composer to use as much memory as it needs. This makes the command run without hitting the memory exhausted issue (given you have enough memory on your machine).

To stop forgetting this tip I've added a composer alias in my .zshrc file.

alias composer="COMPOSER_MEMORY_LIMIT=-1 composer"

Now you don't need to worry about this anymore.