php Composer 更新内存限制

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

Composer update memory limit

phplaravelsshcomposer-php

提问by Andrew

I need to run composer update at my hosting so I log in with ssh and try to run comand:

我需要在我的主机上运行 composer update 所以我使用 ssh 登录并尝试运行命令:

composer update

inside /www folder where I have laravel and composer instalation

在 /www 文件夹中,我有 Laravel 和 Composer 安装

but I get error: enter image description here

但我收到错误: 在此处输入图片说明

in contact with my hosting provider they tell me to run command:

与我的托管服务提供商联系时,他们告诉我运行命令:

php -d memory_limit=512M composer update

I run this command but I get: "Could not open file: composer"

我运行这个命令,但我得到:“无法打开文件:作曲家”

What to do? What is the soluton here?

该怎么办?这里的解决方案是什么?

回答by Sven

When you run composer update, the OS will look into the configured paths and try to locate an executable file with that name.

当您运行 时composer update,操作系统将查看配置的路径并尝试定位具有该名称的可执行文件。

When running php composer update, the composerstring is treated as a parameter to PHP, which is not searched in any paths. You have to provide the full path in order to run it.

运行时php composer update,该composer字符串被视为 PHP 的参数,不会在任何路径中搜索。您必须提供完整路径才能运行它。

Running which composerwill tell you where the OS finds the composer executable, and then you simply use the full path in the PHP command:

运行which composer将告诉您操作系统在哪里找到 composer 可执行文件,然后您只需在 PHP 命令中使用完整路径:

$>which composer
/usr/local/bin/composer

$>php -d memory_limit=512M /usr/local/bin/composer update
...

Note that 512MB might be too few. My perception is that it will happily take 1GB or more, depending on the number of dependencies you use and the variety of versions that you theoretically allow, i.e. if you allow Symfony ~2.3, then you make Composer deal with a lot more possible versions compared to using ~2.7.

请注意,512MB 可能太少了。我的看法是,它会很高兴地需要 1GB 或更多,这取决于您使用的依赖项数量以及您理论上允许的版本种类,即如果您允许 Symfony ~2.3,那么与使用相比,您会让 Composer 处理更多可能的版本~2.7.

Also note that running Composer on the production machine is not the best idea. You would have to have access to Github, maybe provide access credentials, have VCS tools installed, and you will easily break your site if any of the remote hosting servers is offline during your update. It is a better idea to use Composer on a deployment system that does all the preparation, and then moves all the files onto the production server.

另请注意,在生产机器上运行 Composer 并不是最好的主意。您必须有权访问 Github,可能需要提供访问凭据,安装 VCS 工具,如果任何远程托管服务器在更新期间脱机,您将很容易破坏您的站点。最好在完成所有准备工作的部署系统上使用 Composer,然后将所有文件移动到生产服务器上。

Update

更新

It's the year 2020 now, and the way Composer manages its memory has changed quite a bit. The most important thing is that Composer will increase the memory limit by itself if it encounters a limit set too low. This however immediately triggers the problem of running out of memory on machines that have too few memory installed. You can make Composer use less memory by setting the environment variable like COMPOSER_MEMORY_LIMIT=512M, but this will create problems if Composer would need more memory to correctly operate.

现在是 2020 年,Composer 管理其内存的方式发生了很大变化。最重要的是,如果 Composer 遇到设置过低的限制,它会自行增加内存限制。然而,这会立即触发在安装的内存太少的机器上内存不足的问题。您可以通过设置类似 的环境变量使 Composer 使用更少的内存COMPOSER_MEMORY_LIMIT=512M,但是如果 Composer 需要更多内存才能正确运行,这将产生问题。

My main point remains true: Do not run Composer on machines that have too few memory installed. You potentially need 1.5 GB of free memory to be able to update everything.

我的主要观点仍然正确:不要在安装了太少内存的机器上运行 Composer。您可能需要 1.5 GB 的可用内存才能更新所有内容。

回答by diamondsea

Set it to use as much memory as it wants with:

将其设置为使用尽可能多的内存:

COMPOSER_MEMORY_LIMIT=-1 composer update

回答by Diego Favero

I am facing problems with composer because it consumes all the available memory, and then, the process get killed ( actualy, the output message is "Killed")

我遇到了 Composer 的问题,因为它消耗了所有可用内存,然后进程被终止(实际上,输出消息是“Killed”)

So, I was looking for a solution to limit composer memory usage.

所以,我正在寻找一种限制作曲家内存使用的解决方案。

I tried ( from @Sven answers )

我试过(来自@Sven 的回答)

$ php -d memory_limit=512M /usr/local/bin/composer update

But it didn't work because

但它没有用,因为

"Composer internally increases the memory_limit to 1.5G."

“Composer 内部将 memory_limit 增加到 1.5G。”

-> Thats from composer oficial website.

-> 来自 composer 官方网站。

Then I found a command that works :

然后我找到了一个有效的命令:

$ COMPOSER_MEMORY_LIMIT=512M php composer.phar update

Althought, in my case 512mb is not enough !

虽然,在我的情况下 512mb 是不够的!

Source : https://www.agileana.com/blog/composer-memory-limit-troubleshooting/

来源:https: //www.agileana.com/blog/composer-memory-limit-troubleshooting/

回答by Cosmo Arun

If there's enough memory composer would internally consume it and run without any problem. No need to specifically tell the composer to do it.

如果有足够的内存,composer 会在内部消耗它并毫无问题地运行。不需要特别告诉作曲家去做。

Have you tried to increase your swap memory, coz it worked for me. I increased the swap memory to 4096Mb (4GB) and now it all looks great to me.

您是否尝试过增加交换内存,因为它对我有用。我将交换内存增加到 4096Mb (4GB),现在我觉得这一切都很棒。

first use "sudo free" to see available memory and swap memory. and configure swap as,

首先使用“ sudo free”查看可用内存和交换内存。并将交换配置为,

For Debian:

对于 Debian:

sudo fallocate -l 4G /swapfile
sudo dd if=/dev/zero of=/swapfile bs=4096k count=1048
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

to make it permenant add this to /etc/fstab file, /swapfile swap swap defaults 0 0

使其永久添加到 /etc/fstab 文件中, /swapfile swap swap defaults 0 0

For CentOS :

对于 CentOS:

[root@myserver]:/# cd /var
[root@myserver]:/var# touch swap.img
[root@myserver]:/var# chmod 600 swap.img
[root@myserver]:/var# mkswap /var/swap.img

[root@myserver]:/var# dd if=/dev/zero of=/var/swap.img bs=4096k count=1000
[root@myserver]:/var# mkswap /var/swap.img 
[root@myserver]:/var# swapon /var/swap.img

you can increase your swap memory by changin bs= 1024k or 2048k or 8096k depending on your physical volume size. use 'swapon' and swapoff commands to see the difference.

您可以通过更改 bs= 1024k 或 2048k 或 8096k 来增加交换内存,具体取决于您的物理卷大小。使用 'swapon' 和 swapoff 命令来查看差异。

check 'swappiness' (60 should do good,)

检查“swappiness”(60 应该很好,)

cat /proc/sys/vm/swappiness

回答by Gerfried

I had to combine COMPOSER_MEMORY_LIMITand memory_limitin the command line:

我不得不在命令行中结合COMPOSER_MEMORY_LIMITmemory_limit

On Windows:

在 Windows 上:

set COMPOSER_MEMORY_LIMIT=99999999999&& php -d memory_limit=-1 composer.phar update

On Linux:

在 Linux 上:

export COMPOSER_MEMORY_LIMIT=99999999999 && php -d memory_limit=-1 composer.phar update

回答by Vladimir Salguero

You can change the memory_limitvalue in your php.ini

您可以更改memory_limitphp.ini 中的值

Try increasing the limit in your php.ini file

尝试增加 php.ini 文件中的限制

Use -1 for unlimited or define an explicit value like 2G

使用 -1 表示无限制或定义一个明确的值,如 2G

memory_limit = -1

Note: Composer internally increases the memory_limit to 1.5G.

注意:Composer 内部将 memory_limit 增加到 1.5G。

Read the documentation getcomposer.org

阅读文档getcomposer.org

回答by Snigdha Sambit Aryakumar

This error can occur especially when you are updating large libraries or libraries with a lot of dependencies. Composer can be quite memory hungry.

尤其是在更新大型库或具有大量依赖项的库时,可能会发生此错误。作曲家可能非常需要内存。

Be sure that your composer itself is updated to the latest version:

确保您的作曲家本身已更新到最新版本:

php composer.phar --self-update

You can increase the memory limit for composer temporarily by adding the composer memory limit environment variable:

您可以通过添加 composer memory limit 环境变量来临时增加 composer 的内存限制:

COMPOSER_MEMORY_LIMIT=128MB php composer.phar update

Use the format “128M” for megabyte or “2G” for gigabyte. You can use the value “-1” to ignore the memory limit completely.

使用格式“128M”表示兆字节或“2G”表示千兆字节。您可以使用值“-1”完全忽略内存限制。

Another way would be to increase the PHP memory limit:

另一种方法是增加 PHP 内存限制:

php -d memory_limit=512M composer.phar update ...

回答by MadHyman

On MAC OS High Siera I ran the below:

在 MAC OS High Siera 上,我运行了以下命令:

MacBook-Pro:asiu Hyman$ php --ini

Returned:

回来:

Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/ext- 
opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini

All answers above are setting the loaded config which does update, but notice additional .ini files parsed has php-memory-limits.ini as a separate file. You have to update this file memeory limit as well. same way open in text editor and change to somehting like 2G. The output on memory limit failure should tell you how much memory it needs to run, just set it to higher than that or -1 for unlimited.

上面的所有答案都设置了会更新的加载配置,但请注意解析的其他 .ini 文件将 php-memory-limits.ini 作为单独的文件。您还必须更新此文件内存限制。同样的方式在文本编辑器中打开并更改为 2G 之类的东西。内存限制失败的输出应该告诉您它需要运行多少内存,只需将其设置为高于该值或 -1 表示无限制。

回答by Gerfried

In my case none of the answers helped. Finally it turned out, that changing to a 64 bit version of PHP (M$ Windows) fixed the problem immediately. All other settings did not change.

就我而言,所有答案都没有帮助。最终结果是,更改为 64 位版本的 PHP (M$ Windows) 立即解决了问题。所有其他设置没有改变。

回答by Rem

How large is your aws server? If it only has 1gb of ram, setting the memory limit of 2gb in php.ini won't help.

你的aws服务器有多大?如果它只有 1gb 的内存,在 php.ini 中设置 2gb 的内存限制将无济于事。

If you can't/don't want to also increase the server side to get more RAM available, you can enable SWAP as well.

如果您不能/不想也增加服务器端以获得更多可用 RAM,您也可以启用 SWAP。

See here for how to enable swap.It enables 4gb, although I typically only do 1GB myself.

请参阅此处了解如何启用交换。它支持 4GB,尽管我自己通常只使用 1GB。

Source: Got from laracast site

来源:来自 laracast 网站