【问题标题】:Cannot update Composer's memory size无法更新 Composer 的内存大小
【发布时间】:2020-01-24 18:23:27
【问题描述】:

我正在尝试通过 Composer 在 Magento 2 上安装扩展,但是当我运行 Composer 更新时,我收到以下错误:

 composer update

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

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

我尝试: php -d memory_limit=-1 composer update 但我得到: Could not open input file: composer

所以我尝试并得到了:

curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 1.9.0) successfully installed to: /home/customer/www/xxx/public_html/composer.phar
Use it: php composer.phar

所以,我认为它已修复,我再次尝试并得到:

php -d memory_limit=-1 composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files

所以我再次尝试作曲家更新并得到:

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

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

再一次,我尝试composer update 并得到 Could not open input file: composer

我又回到了我开始的地方并且非常困惑:/请告知。谢谢。

【问题讨论】:

  • 您达到了大约 2GB 的内存限制。您使用的是 32 位 PHP 吗?通常 Composer 会尝试自己管理它的内存限制,但我假设 Magento 正在创建巨大的依赖关系图。

标签: composer-php magento2


【解决方案1】:

当您使用php -d memory_limit=-1 时,您正在动态设置ini 条目,但仅适用于通过该命令运行的脚本。

您运行此命令的想法接近您想要实现的目标:

php -d memory_limit=-1 composer update

您唯一需要知道的是composer 作为命令工作,因为它位于您的操作系统会查找所有可执行文件的某个位置(很可能是/usr/bin/composer/usr/local/bin/composer 或类似的东西,这个通常被称为PATH)。但是当您尝试运行php composer 时,composer 只是被视为常规文件,您的操作系统不再尝试查看您的可执行路径。

您仍然可以做的是使用命令which,它将返回到该composer 可执行文件的路径。

$ php $(which composer) -V
Composer version 1.8.6 2019-06-11 15:03:05

所以你应该能够通过

实现你的目标
php -d memory_limit=-1 $(which composer) install

用于安装包;和

php -d memory_limit=-1 $(which composer) update

更新。

还请注意:composer 文档中有一篇关于内存限制的完整文章:https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors

这可能会减轻您的工作,更改相关的PHP CLI 设置,或者可以指出您使用

COMPOSER_MEMORY_LIMIT=-1 composer install

COMPOSER_MEMORY_LIMIT=-1 composer update

【讨论】:

  • 所以用 composer 完整路径试了一下,又好像可以了,但是当我尝试 composer update 时,我仍然不断收到内存不足的警告
猜你喜欢
  • 2016-07-06
  • 2018-05-29
  • 2013-08-09
  • 2016-10-12
  • 2016-01-22
  • 2020-08-27
  • 2016-05-20
相关资源
最近更新 更多