当我跑 composer require yab/laravel-scout-mysql-driver
这是我得到的输出:
Using version ^2.40 for yab/laravel-scout-mysql-driver
./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 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
我正在运行 Composer 1.9.2。
这是我使用 -vvv 时输出的最后几行:
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-ircmaxell$password-compat.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-paragonie$constant-time-encoding.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-yab$laravel-scout-mysql-driver.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$class-loader.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-apcu.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-xml.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-gecko-packages$gecko-php-unit.json from cache
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
我的内存限制是 128M。 https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors除了增加我的内存限制之外,似乎没有提供很多见解,但似乎 128M 应该足够了?
php -d memory_limit=-1 /usr/local/bin/composer require yab/laravel-scout-mysql-driver
没有帮助 - 我收到了“允许的内存大小为 1610612736 字节用尽”错误。与 memory_limit=1024M
相同.我做了
php --ini
并从中得到 /usr/local/etc/php/7.1/php.ini
,我对其进行了编辑以将内存限制更改为 1024MB 并得到相同的结果:“允许的内存大小为 1610612736 字节”。奇怪的是,“允许的内存大小”在每个实例中都完全相同。就像我所做的实际上没有改变内存大小。
有任何想法吗?
最佳答案
(可能是) Composer Update failed -- out of memory 的重复
我在相同版本(PHP 7.1,Composer 1.9.x)和完全相同的内存限制(经过调查后在 Composer 中编码/定义)遇到了同样的问题。
所以,当你遇到这种错误时要做的第一件事就是告诉 Composer 不要用变量来限制内存,像这样:COMPOSER_MEMORY_LIMIT=-1 composer require "xxx/yyy"
这是推荐的方式,但有时它是行不通的。
在我的项目中,似乎每次我执行 composer require xxx
时,composer.lock 都会损坏。 .
所以为了“修复”它,我这样做:
vendor
文件夹 ( rm -fr vendor
) composer.lock
( rm composer.lock
) composer.json
包含您的新需求(它应该在那里,因为之前的 composer require
),如果没有,添加它 composer install
此时,要么您将清楚地看到依赖项问题,要么将安装所有内容。
我成功地做到了 2 次。
关于php - Composer : Allowed memory size error when installing package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59978196/