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

I tried installing aws/aws-sdk-php yesterday on one of my Laravel 4 projects using Composer, I cannot remember the event chain exactly, but it was not installed successfully. Since then I get errors that caused Composer to run out of memory - Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 32 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52 .

I increased php.ini memory_limit to -1, and this is still happening, both in my development environment and in the production environment (production of Cent OS 6). Installation completes successfully if I increment memory_limit via the CLI when running composer_update , but it takes forever.

Is there any cache I need to clear so that Composer runs out of memory? I have the feeling that he still tries to install the AWS SDK every time I run an update for the composer.

Composer file

 { "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "require": { "laravel/framework": "4.0.*", "rtablada/package-installer": "dev-master", "mogreet/mogreet-php": "dev-master", "twilio/laratwilio": "dev-master", "balloon/elephant.io": "dev-master", "facebook/php-sdk": "dev-master", "way/generators": "dev-master", "codesleeve/asset-pipeline": "dev-master", "natxet/CssMin": "dev-master" }, "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php", "app/libraries" ] }, "scripts": { "post-install-cmd": [ "php artisan optimize" ], "pre-update-cmd": [ "php artisan clear-compiled" ], "post-update-cmd": [ "php artisan optimize" ], "post-create-project-cmd": [ "php artisan key:generate" ] }, "config": { "preferred-install": "dist" }, "minimum-stability": "dev" } 
+8
php laravel-4 composer-php
source share
6 answers

EDIT: Before proceeding, make sure you are using the latest composer version, you can update it with composer self-update

When running composer update it will calculate the latest gitref for each of your libraries (or the latest version), and then install that version of the library. He will then save these versions in the composer.lock file.

When running composer install it simply installs the versions defined in the composer.lock file.

The reason composer update takes so much time and uses so much memory, because it needs to track every version of the library, compare it with the version you defined in composer.json , and then check all the dependencies of this library. This is a fairly intense process.

I find that a working composer using hhvm (you can install it here ) speeds up the composer update process in bulk.

In addition, you just need to live using high memory and increase it in your php.ini . Make sure you update the file corresponding to your CLI.

EDIT: You should never run composer update in production. You should only update your dependencies during development, and then use composer install to install your last used composer dependency set when you are in a production environment.

+14
source share

An error is currently appearing in Composer due to which the memory will be exhausted.

If you do

 composer install 

Then delete the folder inside the provider

 rm -rf vendor/laravel 

and do

 composer update 

You will get this error. This is a mistake; it should not run out of memory.

Now you can fix it yourself by doing the following:

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

Also, check this thread , they are going to fix it.

+13
source share

try it. This fixed my problem. I assume that it is better to fix this rather than updating the memory.

 sudo composer self-update 
+12
source share

Just enter the following commands:

rm -rf vendor/

rm -rf composer.lock

php composer install --prefer-dist

Should work on devices with low memory or other memory problems.

+3
source share

The reason it took up so much memory was due to Composer's behavior when processing packets and the replace keyword.

The idea of ​​replacing was that it allowed you to do two things:

  • Replace the standard library version with your own version. for example, if you find an example in "symfony / yaml", you can fork it, fix the error, and then release it as the "nightmicu / yaml" package. You can then tell the composer that "nightmicu / yaml" replaces "symfony / yaml". Then any other package that you install that depends on symfony / yaml will be satisfied with the presence of nightmicu / yaml.

  • This allows people to release packages of both individual components and a complete library, for example. the symfony framework package replaces each package of its components.

The problem is that the replace keyword, until about 1 hour ago, worked globally throughout the package.

This means that for popular libraries that have been branched and renamed, there are a huge number of possible versions for installation. This is what caused huge memory usage and it took a lot of time to process.

If you get the latest version of composer.phar, it should now be better, since "replace" now works differently, only working on the packages specified in the root linker. json, that is, you must explicitly use the package in your composer.json so that it is replaced or acts as a replacement, although I myself could not verify it.

+2
source share

The easiest way to fix this on Windows:

Go to: C: \ ProgramData \ ComposerSetup \ bin

Change composer .bat

Change it to:

 @ECHO OFF php -d memory_limit=-1 "%~dp0composer.phar" %* 

Save the file and run:

composer selfupdate

+1
source share

All Articles