Composer 更新内存限制 [英] Composer update memory limit

查看:81
本文介绍了Composer 更新内存限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的主机上运行 composer update 所以我使用 ssh 登录并尝试在我安装了 Laravel 和 composer 的/www 文件夹中运行以下命令:

I need to run composer update at my hosting so I log in with ssh and try to run the following command inside /www folder where I have Laravel and composer installation:

composer update

我收到此错误:

我正在与我的托管服务提供商联系,他们让我运行以下命令:

I'm in contact with my hosting provider, they told me to run the command:

php -d memory_limit=512M composer update

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

I ran this command but I got: "Could not open file: composer"

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

What to do? What is the solution here?

推荐答案

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

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

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

When running php composer update, the composer string 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.

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

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

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

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

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

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.

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

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.

更新

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

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.

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

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 更新内存限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆