Composer running out of memory on every project, Mac OS X

At the present moment there is a bug on Composer causing memory to be exhausted.

If you do

composer install

Then delete a folder inside vendor

rm -rf vendor/laravel

and do

composer update

You'll get this error. It's a bug, it is not supposed to run out of memory.

For now you can fix it for yourself by doing:

php -d memory_limit=-1 /usr/local/bin/composer update

Also, check this thread, they are about to fix this.


EDIT: Before going any further always make sure you're running the latest version of composer, you can update it via composer self-update

When you run composer update it will calculate the most up-to-date gitref for each of your libraries (or the latest release) and then will install that version of the library. It will then store these versions in the composer.lock file.

When you run composer install, it simply installs the versions defined in the composer.lock file.

The reason composer update takes so long and uses so much memory is because it has to trace every library's version, compare it with the version you have defined in your composer.json and then check all of that library's dependencies. This is quite an intensive process.

I find that running composer using hhvm (you can install it here) speeds up the composer update process massively.

Short of that, you just have to live with the high memory usage and increase it in your php.ini file. Make sure you update the one that is relevant for your CLI.

EDIT: You should never run composer update in the production environment. You should only update your dependencies when you're developing, and then use composer install to install your last used set of composer dependencies when you're in a production environment.