[php] Composer killed while updating

I got a problem, I tried to install a new package to my Laravel 4 project. But when I run php composer.phar update I get this:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Killed

I have looked for the problem in the Internet and saw that the memory is the problem, I think I don't have enough RAM available, I've checked this I have about 411mb free. Does composer really need more RAM?

This question is related to php laravel laravel-4 composer-php

The answer is


php -d memory_limit=5G composer.phar update


Increase the memory limit for composer

php -d memory_limit=4G /usr/local/bin/composer update

If like me, you are using some micro VM lacking of memory, creating a swap file does the trick:

#Check free memory before
free -m

mkdir -p /var/_swap_
cd /var/_swap_
#Here, 1M * 2000 ~= 2GB of swap memory.  Feel free to add MORE
dd if=/dev/zero of=swapfile bs=1M count=2000
chmod 600 swapfile
mkswap swapfile
swapon swapfile
#Automatically mount this swap partition at startup
echo "/var/_swap_/swapfile none swap sw 0 0" >> /etc/fstab

#Check free memory after
free -m

As several comments pointed out, don't forget to add sudo if you don't work as root.

btw, feel free to select another location/filename/size for the file.
/var is probably not the best place, but I don't know which place would be, and rarely care since tiny servers are mostly used for testing purposes.


You can try setting preferred-install to "dist" in Composer config.


Unfortuantely composer requires a lot of RAM & processing power. Here are a few things that I did, which combined, made the process bearable. This was on my cloud playpen env.

  1. You may be simply running out of RAM. Enable swap: https://www.digitalocean.com/community/search?q=add+swap (note: I think best practice is to add a seperate partition. Digitalocean's guide is appropriate for their environment)
  2. service mysql stop (kill your DB/mem-hog services to free some RAM - don't forget to start it again!)
  3. use a secondary terminal session running top to watch memory/swap consumption until process is complete.
  4. composer.phar update --prefer-dist -vvv (verbose output [still hangs at some points when working] and use distro zip files). Maybe try a --dry-run too?
  5. Composer is apparently know to run slower in older versions of PHP (e.g. 5.3x). It was still slow in 5.5.9 for me...

I was getting this error in a local Docker environment. I solved it by simply restarting Docker.


Solved on Laravel/Homestead (Vagrant Windows)

  1. Edit Homestead.yaml and increase memory from 2048 to 4096

  2. vagrant up

  3. vagrant ssh

  4. Install Symfony with this line on the folder you choose (must be without files)

    COMPOSER_MEMORY_LIMIT=-1 composer create-project symfony/website-skeleton . -s dev
    

If you're using docker you can use COMPOSER_PROCESS_TIMEOUT

environment:
  COMPOSER_MEMORY_LIMIT: -1
  COMPOSER_PROCESS_TIMEOUT: 2000 #seconds

I've got this error when I ran composer install inside my PHP DOCKER container, It's a memory issue. Solved by increasing SWAP memory in DOCKER PREFERENCES from 512MB to 1.5GB

To do that:

Docker -> Preferences -> Rousources

enter image description here


composer 2 update have reduced the memory usage

composer self-update
composer update
composer require xxx

Here's how I succeeded in installing maatwebsite\excel package from composer in Laravel Framework:

  1. I download composer.json file and composer.lock file from my remote server.
  2. I run composer update from local command prompt (then wait until all the install process finished).
  3. Upload composer.lock file to remote server.
  4. run composer install on remote server (then wait until all process finished).
  5. DONE

I get this problem caused for a package that don't update correctly with wildcards, I use directly the last version and it works finally.

"l3/cas-bundle": "~1.0" -------> "l3/cas-bundle": "1.1.13"


DigitalOcean fix that does not require extra memory - activating swap, here is an example for 1gb:

in terminal run below

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

The above solution will work until the next reboot, after that the swap would have to be reactivated. To persist it between the reboots add the swap file to fstab:

sudo nano /etc/fstab

open the above file add add below line to the file

/var/swap.1 swap swap sw 0 0

now restart the server. Composer require works fine.


Run composer self-update and composer clearcache remove vendor and composer.lock restart your local environment and then run php -d memory_limit=-1 /usr/local/bin/composer install


Fix for AWS ec2 Ubuntu Server Php Memory Value Upgrade For Magento 2.3.X

  • Php 7.2 / 7.3
  • nginx
  • ubuntu
  • composer 1.X
  • mariaDB
  • magento 2.3.X

Error : Updating dependencies (including require-dev) Killed for

  1. Ram Must at least 4GB
  2. Change instance type to suitable or Upgrade Ram
  3. Php Memory Value change
  4. Server Restart
  5. Try to install the same package again

PHP value update may locate under '/etc/php/7.2/fpm/php.ini' depend on your server and PHP fpm X.XX version

Using Seed command 'change as your server requires' on my case >> /etc/php/7.2/fpm/php.ini

memory limit type as "3.5G" or "3500MB" Php 7.2.X

sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.2/fpm/php.ini
  

Php 7.3.X

  sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.3/fpm/php.ini

Test if applied on 'free -h' command

    free -h

Install-Package Again#

Install extension via Composer

go to your Magento 2 installation directory

cd /var/www/html/

with 'superuser' privileges

sudo su

Start installation

composer require XXXXXX/XXXXXXX

Enable Module s

php bin/magento module:enable XXXXXX/XXXXXXX


php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
Restart
sudo reboot

Enjioy


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Examples related to laravel-4

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration 'Malformed UTF-8 characters, possibly incorrectly encoded' in Laravel Can I do Model->where('id', ARRAY) multiple where conditions? how to fix stream_socket_enable_crypto(): SSL operation failed with code 1 Rollback one specific migration in Laravel How can I resolve "Your requirements could not be resolved to an installable set of packages" error? Define the selected option with the old input in Laravel / Blade Redirect to external URL with return in laravel laravel the requested url was not found on this server

Examples related to composer-php

Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted How to change PHP version used by composer PHP7 : install ext-dom issue PHP error: "The zip extension and unzip command are both missing, skipping." Composer: file_put_contents(./composer.json): failed to open stream: Permission denied require(vendor/autoload.php): failed to open stream How to install a specific version of package using Composer? Composer update memory limit Cannot create cache directory .. or directory is not writable. Proceeding without cache in Laravel To enable extensions, verify that they are enabled in those .ini files - Vagrant/Ubuntu/Magento 2.0.2