3

When deploying my Symfony2 project to my server I occassionally get the following error:

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): 
fork failed - Cannot allocate memory' in 
in phar:///var/www/xyz.co.uk/releases/20130320161122/composer.phar/vendor/
symfony/console/Symfony/Component/Console/Application.php:982

Update

Full error message is below which occurs after --> Updating Composer dependencies:

*** [err :: x.xx.xx.xxx] PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///var/www/xyz.co.uk/releases/20130320161815/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:982
*** [err :: x.xx.xx.xxx] Stack trace:
*** [err :: x.xx.xx.xxx] #0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///var/www...', 982, Array)
*** [err :: x.xx.xx.xxx] #1 phar:///var/www/xyz.co.uk/releases/20130320161815/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(982): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
*** [err :: x.xx.xx.xxx] #2 phar:///var/www/xyz.co.uk/releases/20130320161815/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(900): Symfony\Component\Console\Application->getSttyColumns()
*** [err :: x.xx.xx.xxx] #3 phar:///var/www/xyz.co.uk/releases/20130320161815/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php(865): Symfony\Component\Console\ in phar:///var/www/xyz.co.uk/releases/20130320161815/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php on line 982
*** [deploy:update_code] rolling back
failed: "sh -c 'sh -c '\\''cd /var/www/xyz.co.uk/releases/20130320161815 && php composer.phar update --no-scripts --verbose --prefer-dist'\\'''" on x.xx.xx.xxx

This doesn't happen ALL the time but just sometimes. I've allocated 256M in my apache and cli php.ini file on the server but still sometimes receive the error.

How much memory does Symfony require? Do I need to increase it further? I thought this would be enough.

user1961082
  • 1,015
  • 17
  • 41

3 Answers3

1

According to this post on GitHub: https://github.com/composer/composer/issues/945 It looks like you'll need at least 1GB of memory available to PHP.

Symfony is quite the memory hog and while 1Gb may sound ridiculous, for the type of processing it's performing it's most definitely not out of the question. If it's telling you you're out of memory, your only option is to add more memory.

You might also want to check back in a week or so and see if they haven't patched up some sort of memory leak as well.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Joshua Burns
  • 8,268
  • 4
  • 48
  • 61
  • 2
    1GB seems a lot. I have development, staging and production servers. My development and staging servers only have 512MB RAM in total as they are just for testing purposes and my production has 4GB. Do I really need to increase development and staging to 1GB? – user1961082 Mar 20 '13 at 16:17
  • Symphony's stance on this has always been to up your memory limit. Beyond that, there really is no way around this... You could potentially see if there is a slightly older version available which greatly cuts down on memory usage... – Joshua Burns Mar 20 '13 at 16:21
  • 1
    Just a quick note to mention that the OP asks about [Symfony](http://symfony.com/), not [Symphony](http://getsymphony.com/). – Mick Mar 21 '13 at 12:08
1

Yes, Symfony was always heavier than most frameworks out there but this error is kinda ridiculous. I'm saying this because my production machine has 512MB of RAM in total and 128M is allocated to PHP - and, still, application performs excellent.

Now, because complexity does play a major role here, where does you error occur? During the cache warm-up/clean? Are you trying to run some custom console command?

Also, have you tried installing APC? My application went blazing after doing that :)

Jovan Perovic
  • 19,846
  • 5
  • 44
  • 85
  • I've updated my original question with the full error message, it's within --> Updating Composer dependencies. Can you please point in the direction where I can install APC? Thanks – user1961082 Mar 20 '13 at 16:59
  • 1
    http://www.leonardaustin.com/technical/install-apc-on-ubuntu-with-php-5-3 - this link explains how to install it. One thing that crossed my mind is that maybe you should update your composer binary? Maybe you could give it a shot with `php composer.phar self-update`? – Jovan Perovic Mar 20 '13 at 17:39
0

Some symfony deployments needs a lot memory for update repositories. Also if you use capifony you could get a lot memory errors. The trick for deploy in small VPS or dedicated with less than 1-2 GB of RAM is create a SWAP where you will get store the memory need. So for example you can try creating 1 GB of swap with this commands:

# /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
# /sbin/mkswap /var/swap.1
# /sbin/swapon /var/swap.1
shakaran
  • 10,612
  • 2
  • 29
  • 46