php 作曲家在更新时被杀

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20667761/
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 03:24:12  来源:igfitidea点击:

Composer killed while updating

phplaravellaravel-4composer-php

提问by user3038158

I got a problem, I tried to install a new package to my Laravel 4 project. But when I run php composer.phar updateI get this:

我遇到了一个问题,我试图在我的 Laravel 4 项目中安装一个新包。但是当我跑步时,php composer.phar update我得到了这个:

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

I have looked for the problem in the Internet and saw that the memory is the problem, I think I don't have enough RAM available, I've checked this I have about 411mb free. Does composer really need more RAM?

我在互联网上寻找问题,发现内存有问题,我想我没有足够的可用内存,我已经检查过我有大约 411mb 可用空间。作曲家真的需要更多内存吗?

回答by Andreas

The "Killed" message usually means your process consumed too much memory, so you may simply need to add more memory to your system if possible. At the time of writing this answer, I've had to increase my virtual machine's memory to at least 768MB in order to get composer updateto work in some situations.

“Killed”消息通常意味着您的进程消耗了太多内存,因此您可能只需要在可能的情况下向系统添加更多内存。在撰写此答案时,我必须将虚拟机的内存增加到至少 768MB,以便composer update在某些情况下开始工作。

However, if you're doing this on a live server, you shouldn't be using composer updateat all. What you should instead do is:

但是,如果您在实时服务器上执行此操作,则根本不应使用composer update。你应该做的是:

  1. Run composer updatein a local environment (either your local physical machine, or a development virtual machine)
  2. Upload or git pushthe composer.lock file
  3. Run composer installon the live server
  1. composer update在本地环境中运行(本地物理机或开发虚拟机)
  2. 上传或git pushcomposer.lock 文件
  3. composer install在实时服务器上运行

composer installwill then read from the .lock file, fetching the exact same versions every time rather than finding the latest versions of every package. This makes your app less likely to break, and composer uses less memory.

composer install然后将从 .lock 文件中读取,每次获取完全相同的版本,而不是查找每个包的最新版本。这使您的应用程序不太可能崩溃,并且作曲家使用更少的内存。

Read more here: https://getcomposer.org/doc/01-basic-usage.md#installing-with-composer-lock

在此处阅读更多信息:https: //getcomposer.org/doc/01-basic-usage.md#installing-with-composer-lock

回答by Balmipour

If like me, you are using some micro VM lacking of memory, creating a swap file does the trick:

如果像我一样,您正在使用一些内存不足的微型 VM,那么创建交换文件就可以解决问题:

free -m
mkdir -p /var/_swap_
cd /var/_swap_
#Here, 1M * 2000 ~= 2GB of swap memory
dd if=/dev/zero of=swapfile bs=1M count=2000
mkswap swapfile
swapon swapfile
chmod 600 swapfile
echo "/var/_swap_/swapfile none swap sw 0 0" >> /etc/fstab
#cat /proc/meminfo
free -m

btw, feel free to select another location/filename/size for the file.
/varis probably not the best place, but I don't know which place would be, and rarely care since tiny servers are mostly used for testing purposes.

顺便说一句,请随意为文件选择另一个位置/文件名/大小。
/var可能不是最好的地方,但我不知道会是哪个地方,而且很少关心,因为小型服务器主要用于测试目的。

回答by alirobe

Unfortuantely composer requires a lot of RAM & processing power. Here are a few things that I did, which combined, made the process bearable. This was on my cloud playpen env.

不幸的是,作曲家需要大量 RAM 和处理能力。以下是我所做的一些事情,它们结合在一起,使这个过程变得可以忍受。这是在我的云游戏围栏环境中。

  1. You may be simply running out of RAM. Enable swap: https://www.digitalocean.com/community/search?q=add+swap(note: I think best practice is to add a seperate partition. Digitalocean's guide is appropriate for their environment)
  2. service mysql stop(kill your DB/mem-hog services to free some RAM - don't forget to start it again!)
  3. use a secondary terminal session running topto watch memory/swap consumption until process is complete.
  4. composer.phar update --prefer-dist -vvv(verbose output [still hangs at some points when working] and use distro zip files). Maybe try a --dry-runtoo?
  5. Composer is apparently know to run slower in older versions of PHP (e.g. 5.3x). It was still slow in 5.5.9 for me...
  1. 您可能只是用完了 RAM。启用交换:https://www.digitalocean.com/community/search?q=add+ swap (注意:我认为最好的做法是添加一个单独的分区。Digitalocean 的指南适合他们的环境)
  2. service mysql stop(杀死您的 DB/mem-hog 服务以释放一些 RAM - 不要忘记再次启动它!)
  3. 使用运行的辅助终端会话top来观察内存/交换消耗,直到进程完成。
  4. composer.phar update --prefer-dist -vvv(详细输出 [在工作时仍会在某些时候挂起] 并使用发行版 zip 文件)。也许也试试--dry-run
  5. Composer 显然在旧版本的 PHP(例如 5.3x)中运行速度较慢。对我来说,5.5.9 仍然很慢......

回答by Hemamalini

DigitalOcean fix that does not require extra memory - activating swap, here is an example for 1gb:

不需要额外内存的 DigitalOcean 修复 - 激活交换,这是 1GB 的示例:

in terminal run below

在终端运行下面

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

The above solution will work until the next reboot, after that the swap would have to be reactivated. To persist it between the reboots add the swap file to fstab:

上述解决方案将在下一次重新启动之前有效,之后必须重新激活交换。要在两次重启之间保留它,请将交换文件添加到 fstab:

sudo nano /etc/fstab

open the above file add add below line to the file

打开上面的文件将下面的行添加到文件中

/var/swap.1 swap swap sw 0 0

now restart the server. Composer require works fine.

现在重新启动服务器。作曲家需要工作正常。

回答by farnoosh

Run composer self-updateand composer clearcacheremove vendor and composer.lock restart your local environment and then run php -d memory_limit=-1 /usr/local/bin/composer install

运行composer self-updatecomposer clearcache删除 vendor 和 composer.lock 重新启动本地环境,然后运行 php -d memory_limit=-1 /usr/local/bin/composer install

回答by GiorgosK

You can try something like this

你可以试试这样的

php -d memory_limit=4G /usr/local/bin/composer update

Might need to reboot after this change

此更改后可能需要重新启动

回答by juananruiz

I get this problem caused for a package that don't update correctly with wildcards, I use directly the last version and it works finally.

我得到这个问题是因为一个包没有用通配符正确更新,我直接使用了最后一个版本,它终于可以工作了。

"l3/cas-bundle": "~1.0" -------> "l3/cas-bundle": "1.1.13"

"l3/cas-bundle": "~1.0" -------> "l3/cas-bundle": "1.1.13"

回答by Inoubli

I've got this error when I ran composer installinside my PHP DOCKER container, It's a memory issue. Solved by increasing SWAP memory in DOCKER PREFERENCES from 512MB to 1.5GB

当我composer install在 PHP DOCKER 容器中运行时出现此错误,这是一个内存问题。通过将 DOCKER PREFERENCES 中的 SWAP 内存从 512MB 增加到 1.5GB 来解决

回答by max4ever

If you're using docker you can use COMPOSER_PROCESS_TIMEOUT

如果您使用 docker,则可以使用COMPOSER_PROCESS_TIMEOUT

enter image description here

在此处输入图片说明

回答by davidjimenez75

Solved on Laravel/Homestead (Vagrant Windows)

在 Laravel/Homestead (Vagrant Windows) 上解决

1) Edit Homestead.yaml and increase memory from 2048 to 4096

1)编辑Homestead.yaml,将内存从2048增加到4096

2) vagrant up

2)流浪

3) vagrant ssh

3)流浪的ssh

4) Install Symfony with this line on the folder you choose (must be without files)

4)在你选择的文件夹上用这一行安装Symfony(必须没有文件)

COMPOSER_MEMORY_LIMIT=-1 composer create-project symfony/website-skeleton . -s dev