Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted

PhpSymfonyComposer Php

Php Problem Overview

I am trying to add HWIOAuthBundle to my project by running the below command.

composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

HWIOAuthBundle github:

When I try to run composer require I am getting the out of memory error.

> Using version ^0.6.0@dev for hwi/oauth-bundle Using version ^1.2@dev > for php-http/guzzle6-adapter Using version ^1.10@dev for > php-http/httplug-bundle ./composer.json has been updated 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.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220 > > Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried > to allocate 67108864 bytes) in > phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220

I tried setting the memory_limit to 2G in my php.ini file but did not work. I found my php.ini by running php -i | grep php.ini

Php Solutions

Solution 1 - Php

To get the current memory_limit value, run:

php -r "echo ini_get('memory_limit').PHP_EOL;"

Try increasing the limit in your php.ini file (ex. /etc/php5/cli/php.ini for Debian-like systems):

; Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1

Or, you can increase the limit with a command-line argument:

php -d memory_limit=-1 composer.phar require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

To get loaded php.ini files location try:

php --ini

Another quick solution:

php composer.phar COMPOSER_MEMORY_LIMIT=-1 require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

Or just:

COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

Solution 2 - Php

In my case I was trying to require this package when I got this error.

You can run like this, and you don't have to update the PHP INI file:

COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel

Solution 3 - Php

Another solution from the manual:

Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:

COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>

Or in my case

composer <...>

Solution 4 - Php

Same problem, none of anything related to "memory_limit" worked, but..

composer self-update --2

..solved my problem. (upgrade: 1.10.17 -> 2.0.4)

Solution 5 - Php

On Windows 10;

Goto C:\ProgramData\ComposerSetup\bin

Edit: composer.bat and add memory_limit=-1 in the last line as shown below.

@echo OFF
:: in case DelayedExpansion is on and a path contains ! 
php -d memory_limit=-1 "%~dp0composer.phar" %*

Problem solved ;)

Solution 6 - Php

Since none of the previous answers included set it took me a bit to figure out how to do it in Windows without altering the php.ini, but here's what worked for me:

composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

Solution 7 - Php

I have bypassed the problem in a Homestead Laravel (vagrant) virtual machine running the composer commands preceded by COMPOSER_MEMORY_LIMIT=-1:


To update Composer:

COMPOSER_MEMORY_LIMIT=-1 composer update

To install a package:

COMPOSER_MEMORY_LIMIT=-1 composer require spatie/laravel-translatable

Solution 8 - Php

For this error in macOS Catalina and macOS Big Sur use this line:

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

I used this line to update on Symfony 5. This command also worked with laravel 7.

Solution 9 - Php

Just set the memory_limit specifying the full route of your composer.phar file and update, in my case with the command:

php -d memory_limit=-1 C:/wamp64/composer.phar update

Solution 10 - Php

Sometimes the problem is in the composer memory limit. In my case, I tried increasing the php memory limit but still got the error. You can use COMPOSER_MEMORY_LIMIT=-1 to get around that. Use it as a prefix:

COMPOSER_MEMORY_LIMIT=-1 composer require the/library

You have to prefix it again in the future.

Hope this helps.

Solution 11 - Php

It was recently identified that Composer consumes high CPU + memory on packages that have a lot of historical tags. See composer/composer#7577

A workaround to this problem is using symfony/flex or

composer global require rubenrua/symfony-clean-tags-composer-plugin

Solution 12 - Php

Just in case you get a composer error with:

> Could not open input file: composer


php -d memory_limit=-1 /usr/local/bin/composer require ...

Solution 13 - Php

For skipping memory limit and version error use the code below:

COMPOSER_MEMORY_LIMIT=-1 composer require <package-name> --ignore-platform-reqs

Solution 14 - Php

what about windows?

i use windows 10 and this command worked for me,

php -d memory_limit=-1 "C:\ProgramData\ComposerSetup\bin\composer.phar" update

Solution 15 - Php

Composer 2.0 preview is available now: Fixed issue for me. You can set up a preview with composer self-update --preview

EDIT: Composer 2 with memory tuning released

Solution 16 - Php

> You can use a specific php Version when running Composer

If, like me, for some reason, you are using PHP 32 bits even though your computer is 64 bits, this will always limit the amount of memory allocated to Composer. I solved my problem this way:

  • Install a 64 bits php version somewhere on your computer (let's say in C:/php64)
  • In composer (using cygwin in my case), run:

COMPOSER_MEMORY_LIMIT=-1 C:/php64/php.exe ../composer.phar update

Solution 17 - Php

in windows by xampp i just changed:


in php.ini to:

memory_limit =-1

then restart the Apache by xampp

this is the result:

; Maximum amount of memory a script may consume
memory_limit =-1

Solution 18 - Php

On Mac php 7.4


php --ini

Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,

If Additional .ini files parsed: memory_limit needs to be changed in


As Jose Seie writes, set memory to

memory_limit = -1 or memory_limit = 1G

Solution 19 - Php

Just want to share my situation on this matter.

Problem context:

  1. Running composer in a vagrant box.
  2. Was getting this message after try to run composer require "laravel-doctrine/orm:~1.4.13":

> Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52 Check for more info on how to handle out of memory errors.

  1. Have tried setting php.ini memory limit to -1. (still not working).


  1. Apparently my composer.json and composer.lock has some issues. Ran $ composer validate, and the result was: "The lock file is not up to date with the latest changes in composer.json, it is recommended that you run composer update."

  2. So I ran $ composer update, and all dependencies are resolved. Imho, when the dependencies has some issues, maybe the tree building is out of sync, hence the out of memory issue.

Hope this helps anyone out there.

Solution 20 - Php

To override this and fix the issue on your local machine you can do the following changes within your php.ini configuration file.

  1. To locate your php.ini configuration file you can use the following command: php --ini

After running this command you should see an output like the following:

Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File:         /usr/local/etc/php/7.3/php.ini <---- note the path
Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.3/conf.d/ext-opcache.ini

The file we want to change is the Loaded Configuration.

  1. Open and search for the memory_limit you can set the memory_limit = -1 to give an unlimited amount of memory to PHP processes or you can set 512MB, 1G, 2G, 5G,....

    $ nano /usr/local/etc/php/7.3/php.ini

locate and set:

$ memory_limit = -1 or memory_limit = 1G

3. After saving your file, you can verify the PHP changes by running this command which will output the current memory settings in your php.ini file:

php -r "echo ini_get('memory_limit').PHP_EOL;"

NOTE: After saving, the new memory will be working. You don't need to do anything else.

More info:

Solution 21 - Php

for Centos 7 use :

COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

Solution 22 - Php

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52 Check for more info on how to handle out of memory errors.

set memory_limit to -1 works for me ;) (vim /etc/php/7.2/cli/php.ini)

Solution 23 - Php

For Macbook: run command sudo nano ~/.bash_profile to edit bash_profile then add alias composer="COMPOSER_MEMORY_LIMIT=-1 composer" in that file, then save and exit.

Hope this will solve the problem; Happy coding!

Solution 24 - Php

I condensed or packaged up the useful and accepted answer here into reusable (zsh) aliases/functions, for quicker and easier-to-remember reuse:

# composer high-memory
composermem() {
  php -r "echo ini_get('memory_limit').PHP_EOL;"
alias composerbig='COMPOSER_MEMORY_LIMIT=-1 composer $1'

(php composer.phar is already aliased to composer on the system).

Solution 25 - Php

I solved this problem using this command COMPOSER_MEMORY_LIMIT=-1

Example: COMPOSER_MEMORY_LIMIT=-1 composer requires larval/ui

Solution 26 - Php

For me, this works on shared hosting.

COMPOSER_MEMORY_LIMIT=-1 composer update

Solution 27 - Php

Make sure to not require a package before making sure the vendor folder exists.

Check if you have done composer install before. You may be just cloned the repository to your machine. So, you have to install the old packages before requiring a new one. Or you may want to include this option --profile to your composer command to see the timing and memory usage information.

Solution 28 - Php

In my case:

Windows 10 and Docker Desktop works:

docker-compose -f .docker/docker-compose.yml exec php env COMPOSER_MEMORY_LIMIT=-1 composer require fideloper/proxy

Solution 29 - Php

You just need to increase memory limit on "php.ini" file to solve the problem

find the "memory_limit" in php.ini file.

just change memory_limit value to 2G like below


to relocate the php file by using below command.

php --ini

Solution 30 - Php

In my case, I was missing a swap partition. More info:

Solution 31 - Php

Actually, if you set memory limit to -1 (unlimited) it should work. Eg:

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

Solution 32 - Php

If increasing memory limit does not help OR you do not have much Memory

On a different machine with high memory

  • Set the memory limit of composer as -1
  • Remove the composer.lock file
  • Run composer install
  • Commit composer.lock file to your repo
  • Then in the server run composer install

The idea is most of the memory is used during calculating/creating composer.lock file, if its created/ready - composer install will not use much memory.

Solution 33 - Php

the options on this page worked for me

To be more precise solution one:

 COMPOSER_MEMORY_LIMIT=-1 composer update

Solution 34 - Php

In my case, my composer version was 1.x which was back-dated. After upgrading the version to 2.x it worked as intended.

Solution 35 - Php

Here is another way to solve this problem under windows, if you use Wampserver. Indeed at the level of wampserver, there are two php.ini files, that of PHP, which one can find in the location C: \ wamp64 \ bin \ php \ phpx.xx \ php.ini and that of Apache , which can be found at location C: \ wamp64 \ bin \ apache \ apachex.xx \ bin \ php.ini. Both of these files have the memory_limit parameter. So to be sure to solve this problem, it is better to set the memory_limit = -1 parameter in both files at once.

Solution 36 - Php

I am using php7.2 and the size is set to memory_limit = 512M by default. to increase the size, you need to locate php.ini.

In Wamp, it is located in C:\wamp64\bin\php\php7.2.23\php.ini. Please watch out for the PHP version as it is the name folder, in my case I have php7.2.23

In Laragon, it is located in C:\laragon\bin\php\php-7.2.23-Win32-VC15-x64\php.ini as was in my case.

If you don't want to allow unlimited space, you can set whatever size that is convenient to you, in my case I did memory_limit = 2G

if you want to allow unlimited space, you can change to memory_limit = -1

Solution 37 - Php

Running composer dump-autoload solves it for me.

Solution 38 - Php

go and find php.ini inside you PHP directory incase of xampp it will be inside xampp/PHP and inside php.ini file update memory_limit:512M to 2048M


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrian ChenView Question on Stackoverflow
Solution 1 - PhpAdamView Answer on Stackoverflow
Solution 2 - PhpodubahView Answer on Stackoverflow
Solution 3 - PhpThomas VangeloovenView Answer on Stackoverflow
Solution 4 - PhpMilla SenseView Answer on Stackoverflow
Solution 5 - PhpDigital HumanView Answer on Stackoverflow
Solution 6 - PhpArno van OordtView Answer on Stackoverflow
Solution 7 - PhpDavide CasiraghiView Answer on Stackoverflow
Solution 8 - PhpjuanitourquizaView Answer on Stackoverflow
Solution 9 - PhpAitor FernandezView Answer on Stackoverflow
Solution 10 - Phpmeow2xView Answer on Stackoverflow
Solution 11 - PhpRuben GonzalezView Answer on Stackoverflow
Solution 12 - PhpMarcus ChristiansenView Answer on Stackoverflow
Solution 13 - PhpAbduhafizView Answer on Stackoverflow
Solution 14 - PhpMohamed HanyView Answer on Stackoverflow
Solution 15 - PhpAnatoly SokolovView Answer on Stackoverflow
Solution 16 - PhpRoubiView Answer on Stackoverflow
Solution 17 - Phpsaber tabatabaee yazdiView Answer on Stackoverflow
Solution 18 - PhpKalle KarlssonView Answer on Stackoverflow
Solution 19 - PhpSteven YipView Answer on Stackoverflow
Solution 20 - PhpJose SeieView Answer on Stackoverflow
Solution 21 - PhpignielView Answer on Stackoverflow
Solution 22 - PhpTed MosbyView Answer on Stackoverflow
Solution 23 - PhpProsanta ChakiView Answer on Stackoverflow
Solution 24 - PhpemjayessView Answer on Stackoverflow
Solution 25 - PhpFaisal AhmedView Answer on Stackoverflow
Solution 26 - PhpAdie RTView Answer on Stackoverflow
Solution 27 - PhpSaud AlfadhliView Answer on Stackoverflow
Solution 28 - PhpVadim IzmalkovView Answer on Stackoverflow
Solution 29 - PhpVignesh PSView Answer on Stackoverflow
Solution 30 - PhpМ.Б.View Answer on Stackoverflow
Solution 31 - PhpKokilView Answer on Stackoverflow
Solution 32 - PhpdavView Answer on Stackoverflow
Solution 33 - PhpIvan EspinosaView Answer on Stackoverflow
Solution 34 - Phpsh6210View Answer on Stackoverflow
Solution 35 - PhpFidèle W. AVIView Answer on Stackoverflow
Solution 36 - PhpChetam OkaforView Answer on Stackoverflow
Solution 37 - PhpAbdellah RamadanView Answer on Stackoverflow
Solution 38 - PhpRashid IqbalView Answer on Stackoverflow