I got this error when running composer.phar update
on my VM:
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried t
Composer may sometimes fail on some commands with this message:
PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>
Or in my case :
Fatal error: Out of memory (allocated 1116733440) (tried to allocate 134217728 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Pool.php on line 339
In this case, the PHP memory_limit should be increased.
Note: Composer internally increases the memory_limit to 1.5G.
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
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or, you can increase the limit with a command-line argument:
php -d memory_limit=-1 composer.phar <...>
This issue can also happen on cPanel instances, when the shell fork bomb protection is activated. For more information, see the documentation of the fork bomb feature on the cPanel site.
To get loaded php.ini files location try:
php --ini
Source : (Composer docs)
I'm on a Windows machine and I tried all of the answers from this question, but none of them worked. For me, it FINALLY worked after I ran composer using the 64-bit version of PHP.
To run composer using a local copy of PHP x64 you can do the following:
extension_dir = "ext"
line and any other php extensions you will need (such as extension=gd2
or extension=openssl
). If any other PHP extensions are needed for the update then it will tell you while running the command.Working command:
"C:\path\to\php-7.2.23-Win32-VC15-x64\php.exe" -d memory_limit=-1 "C:/path/to/composer.phar" update
Source: https://ourcodeworld.com/articles/read/816/how-to-solve-composer-install-update-error-virtualalloc-failed-0x00000008
Increasing the memory_limit
value on my php.ini
did not solve my problem.
What I did was:
And that did the trick!
In my case, I was facing this error because of running composer install
inside vagrant box. Running it inside my host machine didn't cause the issue.
If you are still facing issues after updating your memory limit then the best thing to try is to run:
composer update --lock
This will update your lock file so that composer can run from it if you have changed your composer.json file.
You can now optimally run:
composer update
or
composer install
From my experience, memory errors from composer usually means it is spending too much memory looking for the right combinations of packages to install, especially the version constraints are not specific enough. For example, ^5.2.4 matches 5.3 to 5.3.29, 5.4 to 5.4.45, etc. For each specific version and permutation, composer has to get the package's dependencies to check if all the constraints are met. This is usually when the memory consumption gets huge.
Once the versions have been figured out, the installation phase uses much less memory. The resolved versions for each package are also stored in a composer.lock file so that the specific permutation installed can be replicated in other environments. And this is the potential solution to your issue: run composer update in your dev machine (which should have enough memory), deploy the updated composer.lock, and run composer install on the server.
Composer install will always reference the existing composer.lock for the versions to install for each package, and thus should seldom run into memory issues.
For a reference on how to express version constraints in composer.json, check out https://getcomposer.org/doc/articles/versions.md