Last Updated: February 25, 2016
·
11.03K
· moak

When Composer Cannot Allocate Memory

I am using an AWS micro instance with only 600MB ram, and have had the issue where running the composer update command after a few minutes I get an error message along the lines of proc_open(): fork failed - Cannot allocate memory

My first step was setting the memory limit of PHP

If you runphp -r "echo ini_get('memory_limit').PHP_EOL;"and it's something low like 128mb try increasing the limit in your php.ini file (ex. /etc/php5/cli/php.ini)

Now if you still run out of memory you can enable swap, (from this tutorial)

# 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

The first command may take a few seconds to run, be patient. After the swap is enabled I was able to run composer update again.

Hope this helps someone else

4 Responses
Add your response

It really depends on how many dependencies you have, and how many sub-dependencies those have. Had too many issues on micro instances because of low memory, it's easier just to upgrade to a small.

over 1 year ago ·

Sure there's a limit, and of course when it really is necessary you should upgrade. However right now the only time the memory errors occurred are when running composer with a lot of dependencies and so this is just for those of us who are on a budget and want to get the most out of a micro instance ;)

over 1 year ago ·
over 1 year ago ·

My main go to page when composer cannot allocate enough memory on my vps!

over 1 year ago ·