php Composer 更新失败——内存不足
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33299302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Composer Update failed -- out of memory
提问by Aldibe
I got this error when running composer.phar update
on my VM:
composer.phar update
在我的 VM 上运行时出现此错误:
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 144115188075867549 bytes) in phar:///bin/composer.phar/src/Composer/Util/RemoteFilesystem.php on line 179
PHP 致命错误:第 179 行的 phar:///bin/composer.phar/src/Composer/Util/RemoteFilesystem.php 中允许的内存大小为 1073741824 字节(试图分配 144115188075867549 字节)
The composer.json
, if needed:
的composer.json
,如果需要的话:
{
"description" : "The CodeIgniter framework",
"name" : "codeigniter/framework",
"license": "MIT",
"require": {
"php": ">=5.2.4",
"videlalvaro/php-amqplib": "2.5.*"
},
"require-dev": {
"mikey179/vfsStream": "1.1.*",
"videlalvaro/php-amqplib": "2.5.*"
}
}
The VM just recently recovered from a bad disk sector problem, and the guy running the VM said that the VM has been moved to a new disk. There are only Java, PHP, httpd, postgre, rabbitmq and the website itself in my VM, and it already ran perfectly for about 4 months before this happened. I'm using PHP 5.6.11. Can anyone help please?
VM 刚刚从坏磁盘扇区问题中恢复过来,运行 VM 的人说 VM 已移至新磁盘。我的虚拟机中只有 Java、PHP、httpd、postgre、rabbitmq 和网站本身,并且在发生这种情况之前它已经完美运行了大约 4 个月。我正在使用 PHP 5.6.11。有人可以帮忙吗?
采纳答案by Aldibe
Solved by deleting the whole vendor folder, and then doing the composer update again, and it works... somehow. I don't even understand :v
通过删除整个供应商文件夹来解决,然后再次进行作曲家更新,它可以工作......不知何故。我什至不明白:v
回答by Eugen Mihailescu
Check the Composer's troubleshootingwiki, especially the memory limit errors section.
检查Composer 的故障排除wiki,尤其是内存限制错误部分。
For instance, by running the composer like this:
例如,通过像这样运行作曲家:
php -d memory_limit=-1 `which composer` update
I get no error anymore. So it is probably an insufficient memory issue that can be solved inline, without altering your default PHP configuration.
我再也没有错误了。因此,这可能是内存不足的问题,可以内联解决,而无需更改您的默认 PHP 配置。
What the command above does is that it sets the PHP CLI memory limit to "unlimited" (ie. -1) and then it runs the inline composer update
command.
上面的命令所做的是将 PHP CLI 内存限制设置为“无限制”(即 -1),然后运行内联composer update
命令。
Please note that instead of `which composer`you should probably use the real path of your composer.phar
PHP script. The which composer
written inline (like in my example above) will be inline solved to your composer.phar
full path (you may use whatever form you like).
请注意,您可能应该使用PHP 脚本的真实路径而不是`which composer`composer.phar
。该which composer
书面内联(就像在我上面的例子)将在线解决您的composer.phar
完整路径(你可以使用任何形式的你喜欢)。
回答by katiak
The only thing that solve my problem was doing this:
解决我的问题的唯一方法是这样做:
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
REF:作曲家故障排除
回答by squall3d
From my experience, memory errors from composer usually means it is spending too much memory looking for the right combinations of packages to install, especially the version constraints are not specific enough. For example, ^5.2.4 matches 5.3 to 5.3.29, 5.4 to 5.4.45, etc. For each specific version and permutation, composer has to get the package's dependencies to check if all the constraints are met. This is usually when the memory consumption gets huge.
根据我的经验,composer 的内存错误通常意味着它花费了太多内存来寻找要安装的正确组合包,尤其是版本限制不够具体。例如,^5.2.4 匹配 5.3 到 5.3.29、5.4 到 5.4.45 等。对于每个特定的版本和排列,composer 必须获取包的依赖项以检查是否满足所有约束。这通常是内存消耗变得巨大的时候。
Once the versions have been figured out, the installation phase uses much less memory. The resolved versions for each package are also stored in a composer.lock file so that the specific permutation installed can be replicated in other environments. And this is the potential solution to your issue:run composer update in your dev machine (which should have enough memory), deploy the updated composer.lock, and run composer install on the server.
一旦确定了版本,安装阶段使用的内存就会少得多。每个包的解析版本也存储在 composer.lock 文件中,以便安装的特定排列可以在其他环境中复制。这是您问题的潜在解决方案:在您的开发机器(应该有足够的内存)中运行 composer update,部署更新的 composer.lock,并在服务器上运行 composer install。
Composer install will always reference the existing composer.lock for the versions to install for each package, and thus should seldom run into memory issues.
Composer install 将始终引用现有的 composer.lock 为每个包安装的版本,因此很少会遇到内存问题。
For a reference on how to express version constraints in composer.json, check out https://getcomposer.org/doc/articles/versions.md
有关如何在 composer.json 中表达版本约束的参考,请查看https://getcomposer.org/doc/articles/versions.md
回答by chebaby
Memory limit errors
内存限制错误
Composer may sometimes fail on some commands with this message:
Composer 有时可能会在某些命令上失败并显示以下消息:
PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>
Or in my case :
Fatal error: Out of memory (allocated 1116733440) (tried to allocate 134217728 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Pool.php on line 339
PHP 致命错误:XXXXXX 字节的允许内存大小已用完 <...>
或者就我而言:
致命错误:第 339 行的 phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Pool.php 中的内存不足(已分配 1116733440)(试图分配 134217728 字节)
In this case, the PHP memory_limitshould be increased.
在这种情况下,memory_limit应该增加PHP 。
Note: Composer internally increases the memory_limitto 1.5G.
注:作曲家内部增加memory_limit至 1.5G。
To get the current memory_limitvalue, run:
要获取当前memory_limit值,请运行:
php -r "echo ini_get('memory_limit').PHP_EOL;"
Try increasing the limit in your php.inifile (ex. /etc/php5/cli/php.inifor Debian-like systems):
尝试增加php.ini文件中的限制(例如,/etc/php5/cli/php.ini对于类 Debian 的系统):
; Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMITenvironment variable:
Composer 还遵守COMPOSER_MEMORY_LIMIT环境变量定义的内存限制:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or, you can increase the limit with a command-line argument:
或者,您可以使用命令行参数增加限制:
php -d memory_limit=-1 composer.phar <...>
This issue can also happen on cPanel instances, when the shell fork bomb protection is activated. For more information, see the documentationof the fork bomb feature on the cPanel site.
当 shell fork 炸弹保护被激活时,这个问题也可能发生在 cPanel 实例上。有关更多信息,请参阅cPanel 站点上的 fork 炸弹功能文档。
To get loaded php.ini files location try:
要获取加载的 php.ini 文件位置,请尝试:
php --ini
Source : (Composer docs)
来源:(作曲家文档)
回答by Parag
Katiak's answer worked but I had to modify it. You will need 4 GB of free space for this to work on a Linux machine. Make sure you sudo
the commands if you're not root:
Katiak 的回答有效,但我不得不修改它。您需要 4 GB 的可用空间才能在 Linux 机器上运行。sudo
如果你不是 root,请确保你的命令:
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=4096
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
Composer takes alot of memory for certain repositories like Drupal.
Composer 为某些存储库(如 Drupal)占用了大量内存。
Essentially, this creates 4 GB of Swap memory from the hard drive which the CPU can use to complete the composer command.
从本质上讲,这会从硬盘驱动器创建 4 GB 的交换内存,CPU 可以使用它来完成 composer 命令。
The original solution seems to have come from this Github thread but I could be mistaken:
最初的解决方案似乎来自这个 Github 线程,但我可能会误会:
https://github.com/composer/composer/issues/7348#issuecomment-414178276
https://github.com/composer/composer/issues/7348#issuecomment-414178276
To load the swap at boot add the following line in /etc/fstab
要在引导时加载交换,请添加以下行 /etc/fstab
/var/swap.1 none swap sw 0 0
You may want to backup your fstab
file just to be on the safe side.
为了fstab
安全起见,您可能希望备份您的文件。
To reclaim the swap space do this:
要回收交换空间,请执行以下操作:
sudo swapoff -v /var/swap.1
sudo rm /var/swap.1
If you get a message like this after turning on the swap...
如果您在打开交换后收到这样的消息...
swapon: /var/swap.1: insecure permissions 0644, 0600 suggested.
...change the permission if appropriate
...在适当的情况下更改权限
sudo chmod 600 /var/swap.1
回答by Keven
I'm on a Windows machine and I tried all of the answers from this question, but none of them worked. For me, it FINALLY worked after I ran composer using the 64-bit version of PHP.
我在一台 Windows 机器上,我尝试了这个问题的所有答案,但没有一个奏效。对我来说,在我使用 64 位版本的 PHP运行 composer 后,它终于奏效了。
To run composer using a local copy of PHP x64 you can do the following:
要使用 PHP x64 的本地副本运行 composer,您可以执行以下操作:
- Download the zip file from here (I used the VC15 x64 Thread Safe version): https://windows.php.net/download
- Unzip the file
- Copy php.ini-development and rename to php.ini
- Uncomment the
extension_dir = "ext"
line and any other php extensions you will need (such asextension=gd2
orextension=openssl
). If any other PHP extensions are needed for the update then it will tell you while running the command.
- 从这里下载 zip 文件(我使用的是 VC15 x64 线程安全版本):https://windows.php.net/download
- 解压文件
- 复制 php.ini-development 并重命名为 php.ini
- 取消注释该
extension_dir = "ext"
行和您需要的任何其他 php 扩展(例如extension=gd2
或extension=openssl
)。如果更新需要任何其他 PHP 扩展,那么它会在运行命令时告诉您。
Working command:
工作命令:
"C:\path\to\php-7.2.23-Win32-VC15-x64\php.exe" -d memory_limit=-1 "C:/path/to/composer.phar" update
来源:https: //ourcodeworld.com/articles/read/816/how-to-solve-composer-install-update-error-virtualalloc-failed-0x00000008
回答by DannyZB
It's a memory problem, not a storage issue. You are reaching your PHP memory limit.
这是内存问题,不是存储问题。您已达到 PHP 内存限制。
Edit /etc/php.ini and increase the memory limit ( memory_limit = 128M replace with memory_limit = 256M )
编辑 /etc/php.ini 并增加内存限制( memory_limit = 128M 替换为 memory_limit = 256M )
I would suggest you look for the reason composer is using so much memory , and find ways to cut your PHP memory usage :
我建议您寻找 composer 使用这么多内存的原因,并找到减少 PHP 内存使用的方法:
- Upgrade to PHP56 if you haven't already
- Install Zend Opcache ( shares PHP memory between different instances )
- Uninstall any and all unused PECL extensions
- 如果您还没有升级到 PHP56
- 安装 Zend Opcache(在不同实例之间共享 PHP 内存)
- 卸载所有未使用的 PECL 扩展
This is the issue you are having : https://github.com/composer/composer/issues/1898
回答by R Sun
In my case, I was facing this error because of running composer install
inside vagrant box. Running it inside my host machine didn't cause the issue.
就我而言,由于composer install
在 vagrant box中运行,我面临此错误。在我的主机内运行它不会导致问题。
回答by Shadman
You may also get resolved by just removing vendor directory and re-execute composer install command.
您也可以通过删除供应商目录并重新执行 composer install 命令来解决。