Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vladimir's avatar

FORGE- composer update memory allocation

I tried manual to run composer update on digital ocean, where i deployed my repository . I can't increase memory more then 512 MB.

Getting this error:

forge@nikolic:~/default$ sudo composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
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:981
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 981, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(981): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(799): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(760): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(690): Symfony\Component\Console\Application->getTerminalWidth()
#5 phar:///usr/local/bin/com in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 981

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 981

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

Call Stack:
    0.0003     219984   1. {main}() /usr/local/bin/composer:0
    0.0104     392712   2. require('phar:///usr/local/bin/composer/bin/composer') /usr/local/bin/composer:15
    0.0653    3217024   3. Composer\Console\Application->run() phar:///usr/local/bin/composer/bin/composer:43
    0.0709    3526144   4. Symfony\Component\Console\Application->run() phar:///usr/local/bin/composer/src/Composer/Console/Application.php:84
  168.1359  115995232   5. Composer\Console\Application->renderException() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:131
  168.1360  115996128   6. Symfony\Component\Console\Application->renderException() phar:///usr/local/bin/composer/src/Composer/Console/Application.php:179
  168.1366  115996576   7. Symfony\Component\Console\Application->getTerminalWidth() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:690
  168.1366  115996728   8. Symfony\Component\Console\Application->getTerminalDimensions() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:760
  168.1366  115996824   9. Symfony\Component\Console\Application->getSttyColumns() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:799
  168.1366  115998784  10. proc_open() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:981
  168.1367  115999944  11. Composer\Util\ErrorHandler::handle() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:981

forge@nikolic:~/default$
0 likes
20 replies
mikebronner's avatar
Level 16

I've ran into this issue quite a few times. What always fixed it for me was the following from your project folder:

  1. Delete composer cache: sudo rm -R ~/.composer
  2. Delete vendor folder: sudo rm -R vendor
  3. Rebuild the vendor packages: composer update
4 likes
henrique's avatar

Another possibility, unless that is your only dev server, is to never run UPDATE there. Always run composer update on dev, test it to check if nothing is broken and commit/push the composer.lock file. Then on the live server you run

composer install
1 like
faisal.arbain@gmail.com's avatar

my droplets run on 512MB and encountered the same issue. after creating swaps it never occurs again. Since i works on multiple droplets, I end up save the script into Forge's recipes so I can easily create swaps for new droplets.

vladimir's avatar

Talked to Taylor and he suggest to resize to 1GB of ram which i did. No problems since then, site is up and running.

fideloper's avatar

Enabling Swap before installing with composer might be the way to go - I've had to do it on Vaprobash since the VM's have limited amounts of RAM available. Enabling swap lets the system fall back to use hard drive space for extra RAM when RAM is completely used.

(It's slower, but it means composer and other installers won't fail!)

You can see the commands for that here, where the $2 variable is the number of Megabytes of swap you want to enable for swapping.

@mikebronner's response may have worked because logging in and running the commands I believe may be different than running the commands from an automated script, altho I'm not 100% sure on how/why that seems to be.

5 likes
henrique's avatar

If it is a production server, I still strongly recommend to use the method I said above (commit composer.lock and use composer install). If it's dev, the best way would be giving it a bit more ram (usually 1gb is enough), else swap does just fine (I've used 364mb ram with 1gb swap without any problems).

@fideloper the reason for the high memory usage is composer calculating all the dependencies. When he deleted the vendor folder, composer didn't have to take current version into consideration, so it just check remote version and end up using less ram. Still, sooner or later (depending on the amount of dependencies), it will run out of memory even deleting the vendor folder.

Valorin's avatar

Maybe this issue should be reported as a Composer bug - they might be able to add some memory checking, and optimise the memory usage to keep it under the limit.

That said, for a product server - definitely commit composer.lock, and only run composer install --no-dev. It avoids no end of dependency hell pain...

henrique's avatar

@Valorin when I first got this problem, I ended up at the composer issue track at github, this is a knowing issue and they had plans to work on it and by that time they had already get some improvements somewhere (if I recall correctly) but, (again if I recall correctly) it would be hard to have bigger improvements because of how the structure was set, so it would need some rewrites on this and it would be planned for a future major update. This is what I remember from memory of some months ago and since so much time passed and lots of people have this issue I can't seem to find it :( But from what I see they are always suggesting to increase ram (or swap) and no signal of it changing to use less memory :/

bbloom's avatar

Yup, upgraded to 1Gb and composer update worked. Thank you all for posting this Q&A.

codenex's avatar

I know this thread is a little old however since I had a similar issue recently I thought I'd put in some additional information. While the solution posted by mikebronner works on occasion, it will still sometimes fail. Without upgrading to a server with more RAM, the solution is to enable SWAP as indicated by fideloper. While he did link the commands you can find a detailed tutorial specifically from Digital Ocean.

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

1 like
christianrojas's avatar

Same problem here.

Thanks to @mikebronner's response, just added a comand before to delete the compile.php file from storage/framework folder.

  1. Delete composer.php file from storage folder sudo rm storage/framework/compile.php
  2. Delete composer cache: sudo rm -R ~/.composer
  3. Delete vendor folder: sudo rm -R vendor
  4. Rebuild the vendor packages: composer update
1 like
sitesense's avatar

@christianrojas add the script below to your Forge 'Recipes' and run on each server that you create.

It will create a swap file and you'll have no more memory problems:

if [ -f /swapfile ]; then
 echo "Swap file already exists."
else
 sudo fallocate -l 1G /swapfile
  sudo chmod 600 /swapfile
  sudo mkswap /swapfile
  sudo swapon /swapfile
  echo "/swapfile none swap sw 0 0" >> /etc/fstab
  echo "vm.swappiness=30" >> /etc/sysctl.conf
  echo "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf
  echo "Swap created and added to /etc/fstab for boot up."
fi
4 likes
eriktobben's avatar

I am having the same problem with Composer and Memory Limit. Reading through DO guide, there is the following note. Will this be a problem when using @sitesense receipt?

Although swap is generally recommended for systems utilizing traditional spinning hard drives, using swap with SSDs can cause issues with hardware degradation over time. Due to this consideration, we do not recommend enabling swap on DigitalOcean or any other provider that utilizes SSD storage. Doing so can impact the reliability of the underlying hardware for you and your neighbors.

If you need to improve the performance of your server, we recommend upgrading your Droplet. This will lead to better results in general and will decrease the likelihood of contributing to hardware issues that can affect your service.

kamaroly's avatar

Below commands fixed it for me.

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
1 like
jamesfairhurst's avatar

Had the exact same issue and the above commands that creates a swap file fixed it for me

alexmansour's avatar

Hello @sitesense Thanks for your script.

Could you tell what is the first 3 lines (The ones have echo) do?

Thanks.

Please or to participate in this conversation.