Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow updating of composer dependencies, despite --prefer-dist flag

Why does it take up to two minutes for my composer dependencies to update, even when there have been no changes?

A popular suggestion is to append the --prefer-dist flag:

php composer.phar update --prefer-dist 

But this makes no difference in my case. Below is my composer.json file – am I missing something obvious?

{     "name": "my-namespace/symfony",     "type": "project",     "description": "",     "require": {         "php": ">=5.3.3",         "symfony/symfony": "2.3.*",         "doctrine/orm": ">=2.2.3,<2.4-dev",         "doctrine/doctrine-bundle": "1.2.*",         "twig/extensions": "1.0.*",         "symfony/assetic-bundle": "2.3.*",         "symfony/monolog-bundle": "2.3.*",         "sensio/framework-extra-bundle": "2.3.*",         "sensio/generator-bundle": "2.3.*",         "sensio/distribution-bundle": "2.2.*",         "my-namespace/my-bundle": "1.0.*"     },    "repositories": [         {             "type": "vcs",             "url": "http://username:[email protected]/my-bundle.git"         }     ],         "scripts": {         "post-install-cmd": [             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"         ],         "post-update-cmd": [             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"         ]     },     "config": {         "bin-dir": "bin"     },     "minimum-stability": "dev",     "extra": {         "symfony-app-dir": "app",         "symfony-web-dir": "web",         "branch-alias": {             "dev-master": "2.3-dev"         }     } } 
like image 543
Jonathan Avatar asked Oct 11 '13 11:10

Jonathan


People also ask

Why does composer update take so long?

People too often just run update constantly. This makes Composer go through the entire dependency resolving process, regardless of whether or not anything has changed. When you run install , Composer takes the requirements directly from your . lock file, skipping the dependency resolving process.

Why is composer so slow?

Composer update is very slow if you have a lot of dependencies/packages implemented. You should avoid variable versions and think about using a HHVM as server.

How do I update dependencies composer?

Updating dependencies to their latest versions# To update to the latest versions, use the update command. This will fetch the latest matching versions (according to your composer. json file) and update the lock file with the new versions.

How do I run composer with memory limit?

COMPOSER_MEMORY_LIMIT=-1 composer. phar <...> Or, you can increase the limit with a command-line argument: php -d memory_limit=-1 composer.


2 Answers

This problem is often related to xdebug being loaded in your CLI environment. (It doesn't matter if xdebug is enabled or not.)

You can check whether xdebug is enabled using one of the followinc commands.

// Unix php -m | grep xdebug // Windows php -m | findstr xdebug 

Further information on what operations take so long can be gained by enabling maximum verbosity and profiling information. (Replace install with update if you are updating the packages.)

composer install --prefer-dist -vvv --profile 
like image 155
Nicolai Fröhlich Avatar answered Oct 03 '22 13:10

Nicolai Fröhlich


Factors that can slow down Composer:

  • As pointed out, xdebug can affect the performance of Composer. Running composer diagnose will also warn you about this.

  • Running update instead of install. People too often just run update constantly. This makes Composer go through the entire dependency resolving process, regardless of whether or not anything has changed. When you run install, Composer takes the requirements directly from your .lock file, skipping the dependency resolving process. You should only run update during the development lifecycle of your application. And even then, it's not something you have to run daily usually.

  • If you have a specific dependency that you update frequently yourself, you could try simplifying the process by running composer update vendor/package --with-dependencies instead.

  • Setting minimum-stability to dev. This greatly expands the amount of possibilities that the dependency resolver has to consider. You should almost never lower the minimum-stability to dev unless you absolutely have no other choice. Look into alternatives, such as temporarily using a inline @dev flag.

like image 25
alcohol Avatar answered Oct 03 '22 14:10

alcohol