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 13:45

Try that:

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024

/sbin/mkswap /var/swap.1

/sbin/swapon /var/swap.1
查看更多
够拽才男人
3楼-- · 2020-02-07 13:47

I increased the PHP memory_limit from the default 128M to 512M and restart the server. That solved the problem.

查看更多
smile是对你的礼貌
4楼-- · 2020-02-07 13:50

I get into this situation most of the times so normally i used to follow the step of setting the swap memory.

But now i found a simple alternate trick which worked for me.

Run composer update --no-dev Other than composer update

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

have same problem with php composer.phar update on my 512mb hosting.

solved with php composer.phar install

查看更多
时光不老,我们不散
6楼-- · 2020-02-07 13:50

I had a similar issue on the cheapest server (512MB RAM) hosted with DigitalOcean, and I was also running Jenkins CI on the same server. After I stopped the Jenkins instance the composer install command worked (well, to a point, it failed with the mcrypt extension missing besides already being installed!).

Maybe if you have another app running on the server, maybe its worth trying to stop it and re-running the command.

查看更多
干净又极端
7楼-- · 2020-02-07 13:51

Here are the steps to fix the problem: (instant fast SWAP file allocation method used)

Server SWAP Setup (Ubuntu 16.04 SWAP to Fix Out of Memory Errors)

Check if you have swap already, memory and disk size:

    sudo swapon -s
    free -m
    df -h

Make swap file: (change 1G to 4G if you want 4GB SWAP memory)

    sudo fallocate -l 1G /swapfile 

Check swap file:

    ls -lh /swapfile

Assign Swap File:

    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile

Check if swap OK, memory and disk size:

    sudo swapon -s
    free -m
    df -h

Attach Swap File on System Restart:

    sudo nano /etc/fstab
        /swapfile   none    swap    sw    0   0

Adjust Swap File Settings:

    cat /proc/sys/vm/swappiness
    cat /proc/sys/vm/vfs_cache_pressure

    sudo sysctl vm.swappiness=10
    sudo sysctl vm.vfs_cache_pressure=50

    sudo nano /etc/sysctl.conf

SWAP File Priority: (0-100% => 0: Don't put to swap, 100: Put on SWAP and free the RAM)

        vm.swappiness=10

Remove inode from cache: (100: system removes inode information from the cache too quickly)

        vm.vfs_cache_pressure = 50
查看更多
登录 后发表回答