我试图通过运行下面的命令将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 dump-autoload为我解决了这个问题。

其他回答

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.

只需设置memory_limit,指定编写器的完整路由。Phar文件和更新,在我的情况下使用命令:

php -d memory_limit=-1 C:/wamp64/composer.phar update

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

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

有时问题出在作曲家的内存限制上。在我的情况下,我尝试增加php内存限制,但仍然得到错误。 您可以使用COMPOSER_MEMORY_LIMIT=-1来解决这个问题。 把它用作前缀:

COMPOSER_MEMORY_LIMIT=-1 composer require the/library

以后还得再加上前缀。

希望这能有所帮助。

手册中的另一个解决方案:

Composer也尊重由componer_memory_limit环境变量定义的内存限制:

COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>

或者在我的案例中

export COMPOSER_MEMORY_LIMIT=-1
composer <...>