PHP Composer update “cannot allocate memory” error

2020-02-07 13:30发布

I just can't solve this one.

I'm on Linode 1G RAM basic plan. Trying to install a package via Composer and it's not letting me. My memory limit is set to "-1" on PHP.ini

Is there anything else I can do to get this installed?

Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing thujohn/rss (dev-master df80a7d)
    Downloading: 100%         
PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:975
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 975, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(975): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(853): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(818): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(752): Symfony\Component\Console\Application->getTerminalWidth()
#5 phar:///usr/local/bin/com in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 975

Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:975
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 975, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(975): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(853): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(818): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(752): Symfony\Component\Console\Application->getTerminalWidth()
#5 phar:///usr/local/bin/com in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 975

24条回答
聊天终结者
2楼-- · 2020-02-07 14:00
composer update

Loading composer repositories with package information
Updating dependencies (including require-dev)

> mmap() failed: [12] Cannot allocate memory

Update memory on Server and require '4G' Change 4GB Ram [try to change server type or add more ram]

2 Files We need to edit


on command

# cd /var/www/html
# nano .htaccess

and edit "memory_limit 756M” to 4G


Php ini on php 7.0

# cd ~
# php –-ini
# sudo nano /etc/php-7.0.ini

memory_limit = 128M to 4G

#AWS #AMAZONLINUX #MAGENTO2 #PHP7.0

查看更多
甜甜的少女心
3楼-- · 2020-02-07 14:02

Sometimes by self-updating composer it solves the problem

php composer.phar self-update

Cheers

查看更多
再贱就再见
4楼-- · 2020-02-07 14:10

A bit old but just in case someone new is looking for a solution, updating your PHP version can fix the issue.

Also you should be committing your composer.lock file and doing a composer install on a production environment which is less resource intensive.

More details here: https://github.com/composer/composer/issues/1898#issuecomment-23453850

查看更多
做个烂人
5楼-- · 2020-02-07 14:10

As composer troubleshooting guide here This could be happening because the VPS runs out of memory and has no Swap space enabled.

free -m

To enable the swap you can use for example:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
查看更多
姐就是有狂的资本
6楼-- · 2020-02-07 14:10

I tried by just deleting the vendor folder and composer.lock file and then i run the command composer clear-cache and then composer install. So it working without any error.

查看更多
走好不送
7楼-- · 2020-02-07 14:12

I solved the same problem in Vagrant. I increased the value of memory_limit and delete composer cache: sudo rm -R ~/.composer and finally vagrant reload.

查看更多
登录 后发表回答