我试图通过运行下面的命令将HWIOAuthBundle添加到我的项目中。

composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

HWIOAuthBundle github: https://github.com/hwi/HWIOAuthBundle

当我试图运行作曲家要求,我得到了内存错误。

Using version ^0.6.0@dev for hwi/oauth-bundle Using version ^1.2@dev for php-http/guzzle6-adapter Using version ^1.10@dev for php-http/httplug-bundle ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes) in phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220 Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes) in phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220

我尝试在我的php.ini文件中设置内存限制为2G,但没有工作。我找到我的php.ini通过运行php -i | grep php.ini


当前回答

对我来说,这适用于共享托管。

COMPOSER_MEMORY_LIMIT=-1 composer update

其他回答

您可以在运行Composer时使用特定的php版本

如果像我一样,由于某种原因,尽管您的计算机是64位的,但您使用的是32位的PHP,这将总是限制分配给Composer的内存数量。我是这样解决问题的:

在你的电脑上安装一个64位的php版本(比如在C:/php64中) 在composer中(在我的例子中使用cygwin)运行:

C:/php64/php.exe ../作曲家。phar更新

跳过内存限制和版本错误使用下面的代码:

COMPOSER_MEMORY_LIMIT=-1 composer require <package-name> --ignore-platform-reqs

我在这里将有用且被接受的答案压缩或打包成可重用(zsh)别名/函数,以便更快更容易记住重用:

# composer high-memory
composermem() {
  php -r "echo ini_get('memory_limit').PHP_EOL;"
}
alias composerbig='COMPOSER_MEMORY_LIMIT=-1 composer $1'

(php作曲家。Phar已经在系统上别名为composer)。

最近发现,Composer在具有大量历史标记的包上消耗了大量CPU +内存。看到作曲家/作曲家# 7577

这个问题的解决方法是使用symfony/flex或https://github.com/rubenrua/symfony-clean-tags-composer-plugin

composer global require rubenrua/symfony-clean-tags-composer-plugin

在确保供应商文件夹存在之前,请确保不需要包。

检查之前是否安装过composer。您可能只是将存储库克隆到您的机器上。因此,在需要新的包之前,必须先安装旧的包。或者,您可能希望在composer命令中包含这个选项——profile,以查看时间和内存使用信息。