Reputation: 9230
I attempted to install aws/aws-sdk-php
yesterday on one of my Laravel 4 projects using Composer, I cannot remember exactly the chain of events but it did not install successfully. Ever since, I have been receiving errors that Composer has 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 the php.ini memory_limit
to -1 and this still occurs, both in my development and production environments (production is Cent OS 6). Installation completes successfully if I increase the memory_limit
via the CLI when I run composer_update
but it takes an eternity.
Is there some sort of cache that I need to clear to prevent Composer for running out of memory? I have a feeling that it is still trying to install the AWS SDK every time I run composer update.
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"
}
Upvotes: 17
Views: 24811
Reputation: 1906
do not do any thing only try this code if your version is 1.*:
composer self-update --2
i was facing many problem then i given memory_limit : 10G. after that i was getting same issue then i try to update composer version then it gone fix. you can check compser version
composer --version
Upvotes: 0
Reputation: 179
If you're having 8 GB of Ram or more, then you can surely increase the PHP memory_limit to 1 GB or else to 512MB. On your Mac open terminal-
php --ini
php-memory-limits.ini
file.nano /usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
memory_limit = 1G
php -r "echo ini_get('memory_limit').PHP_EOL;"
brew services restart php
And done. Increasing the memory limit also reduces a little bit of composer update
completion time, which is good.
If you wanna speed up composer update
time. Try installing the popular - Prestissimo package.
Upvotes: 3
Reputation: 1962
I ran into this too but I use brew
.
composer --version
brew info composer
brew upgrade composer
...
==> Upgrading 1 outdated package:
composer 1.9.0 -> 1.9.2
==> Upgrading composer
...
which still did not fix my composer require drupal/environment_indicator
Using the php memory limit mentioned by others fixed this finally.
php -d memory_limit=-1 `which composer` require drupal/environment_indicator
Upvotes: 4
Reputation: 1637
Easiest way to fix this on Windows is:
Goto: C:\ProgramData\ComposerSetup\bin
Edit composer.bat
Change it to:
@ECHO OFF
php -d memory_limit=-1 "%~dp0composer.phar" %*
Save the file and run:
composer selfupdate
Upvotes: 0
Reputation: 13485
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.
Upvotes: 30
Reputation: 778
try this. It fixed my problem.I guess better way to fix it rather than update memory.
sudo composer self-update
Upvotes: 17
Reputation: 5803
Easy, type this commands:
rm -rf vendor/
rm -rf composer.lock
php composer install --prefer-dist
Should work for low memory machines or others memory problems
Upvotes: 6
Reputation: 25711
The reason why it was taking so much memory is because of the behaviour of Composer when treating packages and the replace keyword.
The idea behind replace was that it allowed you to do two things:
Replace a standard library version with your own version. e.g. if you find an example in 'symfony/yaml' you could fork it, fix the bug and then release it as a package called "nightmicu/yaml". You could then tell composer that "nightmicu/yaml" replaces "symfony/yaml". Then any other package that you install that depends on "symfony/yaml" will be satisfied by having "nightmicu/yaml".
It allows people to release packages both as single components, as well as a complete library e.g. the symfony framework package replaces each of its components packages.
The problem is that the replace keyword, up to about 1 hour ago, worked globally across the whole of Packagist.
This means that for popular libraries, that have been forked and renamed there is a huge amount of possible versions to install. This is what was causing a huge memory usage, and taking a long time to process.
If you get the latest version of composer.phar, it should be better now, as 'replace' now works differently, by only working on packages named in the root composer.json i.e. you have to explicitly use a package in your composer.json to have it be either replaceable or act as a replacement, though I haven't been able to test it myself.
Upvotes: 2
Reputation: 87769
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.
Upvotes: 22