更新时作曲家被杀

2022-01-08 00:00:00 php laravel composer-php laravel-4

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

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

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

我在 Internet 上查找了问题,发现内存是问题,我认为我没有足够的 RAM 可用,我检查了这个我有大约 411mb 可用空间.composer 真的需要更多内存吗?

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?

推荐答案

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

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 update to work in some situations.

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

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

  1. 在内存限制不那么严重的本地环境中运行 composer update.
  2. 上传或git push composer.lock 文件.
  3. 在实时服务器上运行 composer install.
  1. Run composer update in a local environment (such as directly on your physical laptop/desktop, or a docker container/VM running on your laptop/desktop) where memory limitations shouldn't be as severe.
  2. Upload or git push the composer.lock file.
  3. Run composer install on the live server.

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

composer install will 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.

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

或者,您可以将整个 vendor 目录上传到服务器,完全无需运行 composer install,但是您应该 运行 composer dump-autoload --optimize.

Alternatively, you can upload the entire vendor directory to the server, bypassing the need to run composer install at all, but then you should run composer dump-autoload --optimize.

相关文章