Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorException: proc_open(): fork failed - Cannot allocate memory in phar #945

Closed
yooper opened this issue Jul 26, 2012 · 81 comments
Closed
Labels

Comments

@yooper
Copy link

yooper commented Jul 26, 2012

ErrorException: proc_open(): fork failed - Cannot allocate memory in phar:///var/www/workspace/MyProject/build/composer/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php on line 943

Call Stack:
0.0523 765208 1. {main}() /var/www/workspace/MyProject/build/composer/composer.phar:0
0.0528 763216 2. require('phar:///var/www/workspace/MyProject/build/composer/composer.phar/bin/composer') /var/www/workspace/MyProject/build/composer/composer.phar:15
0.0830 3504584 3. Composer\Console\Application->run() phar:///var/www/workspace/MyProject/build/composer/composer.phar/bin/composer:13
0.0865 3865984 4. Symfony\Component\Console\Application->run() phar:///var/www/workspace/MyProject/build/composer/composer.phar/src/Composer/Console/Application.php:66
31.9725 246198552 5. Symfony\Component\Console\Application->renderException() phar:///var/www/workspace/MyProject/build/composer/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:113
31.9726 246199624 6. Symfony\Component\Console\Application->getTerminalWidth() phar:///var/www/workspace/MyProject/build/composer/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:771
31.9726 246199784 7. Symfony\Component\Console\Application->getSttyColumns() phar:///var/www/workspace/MyProject/build/composer/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:848
31.9727 246202984 8. proc_open() phar:///var/www/workspace/MyProject/build/composer/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:943
31.9728 246204736 9. Composer\Util\ErrorHandler::handle() phar:///var/www/workspace/MyProject/build/composer/composer.phar/src/Composer/Util/ErrorHandler.php:0

@yooper
Copy link
Author

yooper commented Jul 26, 2012

In order to resolve this issue I had to make sure there was over 1 gig of memory available.

@fixe
Copy link

fixe commented Aug 1, 2012

I was also having this issue but increasing the PHP memory_limit solved the problem.

@raulfraile
Copy link

Same here:

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:943
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 943, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(943): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(848): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(771): Symfony\Component\Console\Application->getTerminalWidth()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(113): Symfony\Component\Console\Application->renderException(Object(ErrorException), Object(Symfo in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 943

Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 943

ErrorException: proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 943

Call Stack:
    0.0001     620632   1. {main}() /usr/local/bin/composer:0
    0.0032     727952   2. require('phar:///usr/local/bin/composer/bin/composer') /usr/local/bin/composer:15
    0.0187    3168240   3. Composer\Console\Application->run() phar:///usr/local/bin/composer/bin/composer:13
    0.0211    3485008   4. Symfony\Component\Console\Application->run() phar:///usr/local/bin/composer/src/Composer/Console/Application.php:66
   13.2099  135622120   5. Symfony\Component\Console\Application->renderException() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:113
   13.2099  135622968   6. Symfony\Component\Console\Application->getTerminalWidth() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:771
   13.2099  135623064   7. Symfony\Component\Console\Application->getSttyColumns() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:848
   13.2099  135625208   8. proc_open() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:943
   13.2100  135626416   9. Composer\Util\ErrorHandler::handle() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:943

More info about the system:

php -v
PHP 5.3.10 (cli) (built: Feb 20 2012 16:56:36) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

@kingcrunch
Copy link
Contributor

Got the same error two times, but can say: It work around an hour ago (without any change on the setup) and now in the third try it works again (without any change at all).

$ php -v
PHP 5.4.4-4~precise+1 (cli) (built: Aug  6 2012 13:01:46) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

Update:

OK, forget it. I forgot to enable the swap again... The machine really ran out of memory...

@advancingu
Copy link

Had the same issue when trying to do a deployment to an Amazon AWS EC2 Micro instance. These instances have only 613MB of memory in total so composer fails to allocate enough memory for an update to run. Upgrading to a Small instance with 1.7GB of total memory got rid of the issue.

@Elijen
Copy link

Elijen commented Sep 13, 2012

I have the same issue .... does composer really need so much memory? :-O

@kingcrunch
Copy link
Contributor

I guess it's not composer itself, but anyway: The micro instances on ec2 doesn't have any swap memory (by default) and so the OS kicks the processes, if it runs out of memory. The better solution instead of upgrading to small (because it costs more) is to create a file based swap (at least temporary)

For example.

# /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
# /sbin/mkswap /var/swap.1
# /sbin/swapon /var/swap.1

613M is very less and remember, that not only PHP consumes it. I don't think one can blame composer for it. Can somebody close this issue?

@Seldaek
Copy link
Member

Seldaek commented Sep 14, 2012

People using micro instances should not have problems anymore after updating composer and updating your lock file to the new format, see #1109. If you have memory issues with other things than install, see #600.

@dhrrgn
Copy link

dhrrgn commented Dec 20, 2012

I am running into this issue again. Here is my Dump:

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:969
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///vagrant...', 969, Array)
#1 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(969): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(874): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(798): Symfony\Component\Console\Application->getTerminalWidth()
#4 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(113): Symfony\Component\Console\Application->re in phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php on line 969

Doing a Dry-Run with Profiling returns the following mem usage info:

Memory usage: 25.95MB (peak: 67.15MB), time: 9.21s

@kingcrunch
Copy link
Contributor

Hi,

Just a guess: Do you running this on a AWS-micro? Do you have a swap
enabled?

Regards,
Sebastian

2012/12/20 Dan Horrigan notifications@github.com

I am running into this issue again. Here is my Dump:

PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:969
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///vagrant...', 969, Array)
#1 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(969): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(874): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(798): Symfony\Component\Console\Application->getTerminalWidth()
#4 phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(113): Symfony\Component\Console\Application->re in phar:///vagrant/www/api-v3/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php on line 969

Doing a Dry-Run with Profiling returns the following mem usage info:

Memory usage: 25.95MB (peak: 67.15MB), time: 9.21s


Reply to this email directly or view it on GitHubhttps://github.com//issues/945#issuecomment-11587234.

github.com/KingCrunch

@Seldaek
Copy link
Member

Seldaek commented Dec 20, 2012

@dhorrigan ouch according to the stack trace it looks like the fatal error was triggered while rendering an exception (since that uses proc_open to check for your terminal width). Looks like it's not a php memory limit but rather the machine's memory that ran out, so I would suggest clearing other things, and running it with install instead of update if you can run update somewhere else that has more memory. install from lock file uses very little memory.

@dhrrgn
Copy link

dhrrgn commented Dec 20, 2012

I am running this in a Vagrant box, and there is quite a bit running on it, but this is the first time I have seen it. I will try re-building the box with more memory and see what happens. I will follow up.

@Seldaek
Copy link
Member

Seldaek commented Dec 20, 2012

To be honest 67MB isn't so big. I can see how it's a problem if it fails, but in this day and age a couple hundred megs of peak memory isn't so much to ask for ;)

@dhrrgn
Copy link

dhrrgn commented Dec 20, 2012

Ya, found the problem, the VM only has 6MB of mem available (out of 512MB) so, ya. Haha, I am upping it to have 1GB of memory. Should have checked that first. Carry on.

@kingcrunch
Copy link
Contributor

@Seldaek The micro instances have 590MB and by default no swap. For playing around this works fine, but as soon as some application needs a little bit more it completely breaks. So as mentioned earlier: Creating a swap catches this :) It only takes 10, or 20 MB more.

#945 (comment)

@andremaha
Copy link

@KingCrung is right. Just added swap to my EC2 micro instance as described here.

Now updating dependencies works like a charm.

@ghost
Copy link

ghost commented Feb 15, 2013

@andremaha Perfect! Thank you!! :)

@jmoz
Copy link

jmoz commented Apr 9, 2013

I'm also getting this problem. 1GB Vagrant on a 4GB Macbook Air. Happens even when I'm limiting an update to a specific vendor.

PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:1033
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 1033, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(1033): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(911): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(876): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(810): Symfony\Component\Console\Application->getTerminalWidth()

Can solve it by vagrant halt && vagrant up && vagrant ssh, then running again.

Memory usage: 102.39MB (peak: 427.97MB), time: 104.79s

@adamsmeat
Copy link

@williamn
Copy link

@adamsmeat thanks! I use your solution for my DO instance

@hppycoder
Copy link

@adamsmeat - I can confirm on a stock loaded Ubuntu 12.04 512MB Digital Ocean machine that your solution is what was needed. Symfony2 is now installed and working as desired.

@rolies106
Copy link

@adamsmeat that saved my life, just added 512MB swap space on my EC2 micro instance and the problem is solved.

@Credochen
Copy link

我也遇到这样的问题,是使用vagrant box的环境,初始的内存为512M,增加到2048G后问题解决了。

@prodev42
Copy link

prodev42 commented Feb 8, 2014

encountered this problem using Digital Ocean 512MB slice...had to #945 (comment)

@allaniftrue
Copy link

same here @prodev42

@allaniftrue
Copy link

I tried copying composer.lock unto the live server and works. with the command

php composer.phar --verbose install

@kingcrunch
Copy link
Contributor

@paparts Sounds like you don't versionize the composer.lock? As a rule of thumb: For applications versionize it, for libraries, don't. You shouldn't run update on a live system, because it is quite likely, that sooner or later a package comes in, that breaks your application, without that you've tested it locally. The composer.lock and composer.phar install ensures, that exactly that packages in that versions are installed, that you've development your application against.

@lostguo
Copy link

lostguo commented Apr 22, 2016

Oh,I use swap solve it,thanks

@mohitg-bs
Copy link

mohitg-bs commented May 5, 2016

You can avoid this either by increasing the memory size from php.ini file, which is a wrong option. Better delete the cache and rebuild the packages.

Delete composer cache: `sudo rm -R ~/.composer`
Delete vendor folder: `sudo rm -R vendor`
Rebuild the vendor packages: `composer update`

Or, I can be done by:

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

@kingcrunch
Copy link
Contributor

@mohitg-bs I guess you mixed something up

  • Removing files doesn't free up RAM
  • It's not about PHPs memory_limit, but the (virtual) memory from the entire system. There is no ini setting, that can create you RAM.

@oussaka
Copy link

oussaka commented May 15, 2016

I solved the same problem in Vagrant.

I easily Increased Memory on Vagrant Virtual Machine http://www.josheaton.org/increase-memory-vagrant-virtual-machine/
then, I increased the value of memory_limit
and delete composer cache: sudo rm -R ~/.composer
and finally vagrant reload.

@gnufred
Copy link

gnufred commented Jun 13, 2016

I had the same problem on a Virtual Box running through Vagrant.
Fixed by increasing VBox ram.

Config change from vb.memory = 512 to vb.memory = 1024

@reddimohan
Copy link

I have added swap memory and it solved my issue.

@rgillera
Copy link

You ran out of swap memory, try this

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

@shamun
Copy link

shamun commented Nov 1, 2016

To add a swap file:

Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.
At a shell prompt as root, type the following command with count being equal to the desired block size:
dd if=/dev/zero of=/swapfile bs=1024 count=65536
Setup the swap file with the command:
mkswap /swapfile
To enable the swap file immediately but not automatically at boot time:
swapon /swapfile
To enable it at boot time, edit /etc/fstab to include the following entry:
/swapfile swap swap defaults 0 0
The next time the system boots, it enables the new swap file.

After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.

@dnorenavega-lbx
Copy link

thank you!

@therobyouknow
Copy link

Tips - if adding swap doesn't solve the composer out of memory/couldn't allocate error:

  • Restart your machine after adding swap. I found composer error didn't go away after adding 8G of swap. But after restarting it worked.
  • I also shut down another VM I was running and closed Chrome with too many tabs

(I'm using composer in a development environment on macOS X Sierra 10.12.4 with 16Gb RAM).

@artforlife
Copy link

artforlife commented Apr 5, 2017

Has this been resolved? I have updated the Composer globally. In addition, I created a 1GB swap space per @gillera235 suggestion. I still get the same error. What can I do to troubleshoot it?

If it helps, I am using a free-tier micro EC2 instance.

@macpatel
Copy link

macpatel commented Jun 7, 2017

push the composer.lock file on your server and do

composer --verbose install

this way it didn't take much memory and was superfast to install the updated packges according to versions in the composer.lock file.

@sagarshah16
Copy link

it happens when you have less memory
try these steps
1)service mysql stop
2) run your comment
3)service mysql start

@vjroby
Copy link

vjroby commented Aug 28, 2017

@sagarshah16 What happens if I don't have a mysql service?

@sagarshah16
Copy link

try to find which one of your running services takes more memory space. if it is not mysql.

@sukrosono
Copy link

yeah ig update composer should solve the problem, sadly i update via git bash. It always throw same error to update. So to windows users just make sure use cmd.exe.

@resting
Copy link

resting commented Dec 7, 2017

Hit the error earlier. Was on Ubuntu 16.04 on a EC2 micro instance.
Solved by adding a 1G swap file.

@nadeemse
Copy link

Just followed this link and resolved the issue.

https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04

@sergiohermes
Copy link

$ apt install swapspace 
$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Reference:
http://manpages.ubuntu.com/manpages/xenial/man8/swapspace.8.html

Thank you Jeroen T. Vermeulen

Enthusiasm is the light of knowledge.
Unknown author.
O estusiasmo é luz do conhecimento.
Autor desconhecido.

@richRemer
Copy link

richRemer commented Jan 22, 2018

This issue can be exacerbated by not having memory over-commit enabled. Forking is massively inefficient without memory over-commit. Essentially when you fork, you double the committed memory usage of your current process by creating another identical process. Much of this memory is shared between the parent and child processes, but is copy-on-write, so any writes will cause the shared memory to get copied. When over-commit is enabled, your system allows this duplicated shared memory, but if you write to the shared memory, you might not have enough physical RAM to handle the copy. With over-commit disabled, your system won't allow you to allocate the memory in the first place.

@ctrl-f5
Copy link

ctrl-f5 commented Jul 9, 2018

Getting this error with 1.4GIG available...

$ free -m; composer require --dev phpro/grumphp
              total        used        free      shared  buff/cache   available
Mem:           2000         416        1277          21         305        1405
Swap:             0           0           0
Using version ^0.14.1 for phpro/grumphp
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
  - Installing symfony/dependency-injection (v3.4.11): The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

                                                     
  [ErrorException]                                   
  proc_open(): fork failed - Cannot allocate memory

@Dhoot
Copy link

Dhoot commented Aug 29, 2018

A fix for this problem is to add swap (i.e. paging) space to the instance.

Paging works by creating an area on your hard drive and using it for extra memory, this memory is much slower than normal memory however much more of it is available.

To add this extra space to your instance you type:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1

If you need more than 1024 then change that to something higher.

To enable it by default after reboot, add this line to /etc/fstab:

/var/swap.1 swap swap defaults 0 0

@izshreyansh
Copy link

@dhorrigan ouch according to the stack trace it looks like the fatal error was triggered while rendering an exception (since that uses proc_open to check for your terminal width). Looks like it's not a php memory limit but rather the machine's memory that ran out, so I would suggest clearing other things, and running it with install instead of update if you can run update somewhere else that has more memory. install from lock file uses very little memory.

Thanks so much, Instead of running composer update i did composer install. Which fixed it!

Its better to than having to increase memory size in php.ini or increasing instance memory itself.

@jemerocay
Copy link

Turning the swap on resolved my problem.

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

@er1z
Copy link

er1z commented Oct 19, 2018

How many of you will post something what was written in this thread? @jemerocay, have you read the topic? The same is posted ~10 messages above.

Contributors: close this, please.

@composer composer locked as resolved and limited conversation to collaborators Oct 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests