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


当前回答

Here is another way to solve this problem under windows, if you use Wampserver. Indeed at the level of wampserver, there are two php.ini files, that of PHP, which one can find in the location C: \ wamp64 \ bin \ php \ phpx.xx \ php.ini and that of Apache , which can be found at location C: \ wamp64 \ bin \ apache \ apachex.xx \ bin \ php.ini. Both of these files have the memory_limit parameter. So to be sure to solve this problem, it is better to set the memory_limit = -1 parameter in both files at once.

其他回答

在我的例子中:

Windows 10和Docker Desktop工作:

docker-compose -f .docker/docker-compose.yml exec php env COMPOSER_MEMORY_LIMIT=-1 composer require fideloper/proxy

要获取当前的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

我在这里将有用且被接受的答案压缩或打包成可重用(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的内存限制设置为-1 删除作曲家。锁文件 运行composer install 提交作曲家。锁定文件到您的回购 然后在服务器上运行composer install

这个想法是在计算/创建composer时使用了大部分内存。锁文件,如果它的创建/就绪- composer安装将不会使用太多内存。

Windows 10;

后藤C: \ ProgramData ComposerSetup \ bin

编辑:composer.bat并在最后一行添加memory_limit=-1,如下所示。

@echo OFF
:: in case DelayedExpansion is on and a path contains ! 
setlocal DISABLEDELAYEDEXPANSION
php -d memory_limit=-1 "%~dp0composer.phar" %*

问题解决了;)