我试图通过运行下面的命令将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


当前回答

我已经绕过了Homestead Laravel(流浪)虚拟机运行composer命令之前的COMPOSER_MEMORY_LIMIT=-1的问题:

例子

要更新Composer:

COMPOSER_MEMORY_LIMIT=-1 composer update

安装软件包:

COMPOSER_MEMORY_LIMIT=-1 composer require spatie/laravel-translatable

其他回答

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

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

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

要获取当前的memory_limit值,运行:

php -r "echo ini_get('memory_limit').PHP_EOL;"

尝试增加php.ini文件中的限制(例如/etc/php5/cli/php.ini对于debian类系统):

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

或者,你可以用命令行参数增加限制:

php -d memory_limit=-1 composer.phar require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

要加载php.ini文件,请尝试:

php --ini

另一个快速解决方案:

php composer.phar COMPOSER_MEMORY_LIMIT=-1 require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

或者是:

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

窗户呢?

我用的是Windows 10,这个命令对我来说很管用,

php -d memory_limit=-1 "C:\ProgramData\ComposerSetup\bin\composer.phar" update

由于之前的答案都不包括set,所以我花了一点时间来弄清楚如何在Windows中做到这一点而不改变php.ini,但下面是对我有效的方法:

set COMPOSER_MEMORY_LIMIT=-1
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

这个页面上的选项对我有用

https://www.jesusamieiro.com/php-fatal-error-allowed-memory-size-of-1610612736-bytes-exhausted/

更精确地说,解决方案一:

COMPOSER_MEMORY_LIMIT=-1作曲家更新