PHP Composer 更新“无法分配内存”错误(使用 Laravel 4)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18116261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:00:08  来源:igfitidea点击:

PHP Composer update "cannot allocate memory" error (using Laravel 4)

phplaravellaravel-4composer-php

提问by ericbae

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

我正在使用 Linode 1G RAM 基本计划。试图通过 Composer 安装一个软件包,但它不允许我。我的内存限制在 PHP.ini 上设置为“-1”

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

采纳答案by fl3x7

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

有点旧,但以防万一新人正在寻找解决方案,更新您的 PHP 版本可以解决问题。

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

此外,您应该提交您的 composer.lock 文件并在资源密集程度较低的生产环境中进行 composer 安装。

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

更多细节在这里:https: //github.com/composer/composer/issues/1898#issuecomment-23453850

回答by Aditya Kresna Permana

Looks like you runs out of swap memory, try this

看起来你的交换内存用完了,试试这个

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

as mentioned by @BlackBurn027 on comments below, this solution was described in here

正如@BlackBurn027 在下面的评论中提到的,这里描述了这个解决方案

回答by Umair Hamid

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

作为此处的作曲家故障排除指南 这可能是因为 VPS 内存不足并且没有启用交换空间。

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

Or if above not worked then you can try create a swap file

或者,如果以上不起作用,那么您可以尝试创建一个交换文件

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

回答by Abishek

I have faced the same issue. I am on a AWS Free Microinstance which has less memory. I always try one of the below options and it always works (Before all this please check if you have the latest version of composer installed)

我遇到了同样的问题。我使用的是内存较少的 AWS 免费微实例。我总是尝试以下选项之一,它总是有效(在这一切之前,请检查您是否安装了最新版本的作曲家)

sudo php -dmemory_limit=750M composer.phar update

or remove the contents of the vendor folder and try composer update.

或删除供应商文件夹的内容并尝试作曲家更新。

sudo rm -rf vendor
sudo php -dmemory_limit=750M composer.phar update --no-scripts --prefer-dist
sudo php artisan --dump-autoload

The second option tries to update all the components, if there is no update, it picks up the package from the cache else picks up from the dist

第二个选项尝试更新所有组件,如果没有更新,它从缓存中获取包,否则从 dist 中获取

Note: Please change the memory limit as per your choice.

注意:请根据您的选择更改内存限制。

or

或者

Create a swap partitionand try. Swap partition is the portion of the hard drive that linux uses as virtual memory when it runs out of physical memory. It's similar to the windows swap file only instead of using an actual file, linux uses a partition on the hard drive instead.

创建一个交换分区并尝试。交换分区是 linux 在物理内存用完时用作虚拟内存的硬盘驱动器的一部分。它类似于 windows 交换文件,只是不使用实际文件,linux 使用硬盘驱动器上的分区。

Hope this helps

希望这可以帮助

回答by insign

Easy, type this commands:

很简单,输入以下命令:

rm -rf vendor/

rm -rf vendor/

rm -rf composer.lock

rm -rf composer.lock

php composer install --prefer-dist

php composer install --prefer-dist

Should work for low memory machines

应该适用于低内存机器

回答by Tarik

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

以下是解决问题的步骤:(使用即时快速 SWAP 文件分配方法)

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

服务器交换设置(Ubuntu 16.04 交换以修复内存不足错误)

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)

制作交换文件:(如果你想要4GB的交换内存,把1G改成4G)

    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)

SWAP 文件优先级:(0-100% => 0:不进行交换,100:启用 SWAP 并释放 RAM)

        vm.swappiness=10

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

从缓存中移除 inode:(100:系统从缓存中移除 inode 信息太快)

        vm.vfs_cache_pressure = 50

回答by YannҶ

I had a same issue on vagrant. I fixed it by allcate more memory.

我对流浪汉有同样的问题。我通过分配更多内存来修复它。

 config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", "1024"]
 end

回答by jeidison farias

Try

尝试

it's basically raising the swap memory

它基本上是提高交换内存

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

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

回答by Ayo 'Lana

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

回答by Manjunath A

I tried by just deleting the vendor folderand composer.lockfile and then i run the command composer clear-cacheand then composer install. So it working without any error.

我尝试删除供应商文件夹composer.lock文件,然后运行命令composer clear-cache,然后composer install. 所以它工作没有任何错误。