PHP: composer install or update causes a PHP Fatal error

When running composer install or update I was getting a PHP fatal error because PHP was using more than 512MB:

$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 72 bytes) in phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php on line 123
PHP Stack trace:
PHP 1. {main}() /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar:0
PHP 2. require() /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar:14
PHP 3. Composer\Console\Application->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/bin/composer:43
PHP 4. Symfony\Component\Console\Application->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Console/Application.php:83
PHP 5. Composer\Console\Application->doRun() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:121
PHP 6. Symfony\Component\Console\Application->doRun() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Console/Application.php:117
PHP 7. Symfony\Component\Console\Application->doRunCommand() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:191
PHP 8. Symfony\Component\Console\Command\Command->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:881
PHP 9. Composer\Command\InstallCommand->execute() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:241
PHP 10. Composer\Installer->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Command/InstallCommand.php:110
PHP 11. Composer\Installer->doInstall() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Installer.php:210
PHP 12. Composer\DependencyResolver\Solver->solve() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Installer.php:449
PHP 13. Composer\DependencyResolver\RuleSetGenerator->getRulesFor() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php:166
PHP 14. Composer\DependencyResolver\RuleSetGenerator->addRulesForUpdatePackages() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php:275
PHP 15. Composer\DependencyResolver\RuleSetGenerator->addRulesForPackage() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php:235
PHP 16. Composer\DependencyResolver\RuleSetGenerator->createConflictRule() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php:204

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 72 bytes) in phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php on line 123

Call Stack:
0.0100 385808 1. {main}() /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar:0
0.0103 387560 2. require(‘phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/bin/composer’) /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar:14
0.0308 2886688 3. Composer\Console\Application->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/bin/composer:43
0.0334 3185464 4. Symfony\Component\Console\Application->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Console/Application.php:83
0.0345 3310400 5. Composer\Console\Application->doRun() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:121
0.0354 3389704 6. Symfony\Component\Console\Application->doRun() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Console/Application.php:117
0.0355 3390560 7. Symfony\Component\Console\Application->doRunCommand() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:191
0.0356 3390896 8. Symfony\Component\Console\Command\Command->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:881
0.0360 3394928 9. Composer\Command\InstallCommand->execute() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:241
0.1072 6425464 10. Composer\Installer->run() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Command/InstallCommand.php:110
0.1081 6525856 11. Composer\Installer->doInstall() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Installer.php:210
3.8979 41690568 12. Composer\DependencyResolver\Solver->solve() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/Installer.php:449
3.8985 41756784 13. Composer\DependencyResolver\RuleSetGenerator->getRulesFor() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php:166
3.9001 41901248 14. Composer\DependencyResolver\RuleSetGenerator->addRulesForUpdatePackages() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php:275
3.9001 41903408 15. Composer\DependencyResolver\RuleSetGenerator->addRulesForPackage() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php:235
104.6757 536552128 16. Composer\DependencyResolver\RuleSetGenerator->createConflictRule() phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php:204

This wasn’t caused by an old version of PHP as I was using PHP 5.5.19:

$ php –version
PHP 5.5.19 (cli) (built: Nov 23 2014 20:46:27)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.6, Copyright (c) 2002-2014, by Derick Rethans

So increasing the maximum memory limit in php.ini would probably solve it but more than 512MB just for a composer install seemed a little bit excessive. So since my PHP install had a current version, I checked composer:

$ composer –version
Composer version 1.0.0-alpha8 2014-01-06 18:39:59

OK, it wasn’t that old, but I checked anyway whether there was a newer version and found one:

$ composer selfupdate
Updating to version 029f7093009f621bd20aef98c7bfc61631f18cf1.
Downloading: 100%
Use composer self-update –rollback to return to version 1.0.0-alpha8

After updating to alpha9, I was able to run composer install !! Sometimes fixing your problem is as easy as making sure you use the latest version of all involved software !

It looks like the memory usage of composer was improved in the latest update. But since composer is still using a lot of memory (depending on the packages you have configured), when using it on your development machine, you should set a high memory limit in php.ini and when deploying to your production server it is best to use a composer.lock especially if you’re on shared hosting.

So you should allocate a lot of memory to PHP on your development machine, only run composer update there and only run composer install with a composer.lock file on your deployment machine.

Also, I have tried it but it looks like it helped some people to disable xdebug.

Leave a Reply

Your email address will not be published. Required fields are marked *