Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

composer install or composer update takes minutes instead of seconds

Errorcomposer install runs for minutes and prints almost nothing

Short answer

Run the command once with --profile to see where the time goes. The usual causes are Xdebug staying loaded, running update where install would do, a cache directory that is never kept, packages cloned from git instead of downloaded as archives, and a broken IPv6 route to the download servers.

  • Applies to Composer 2, PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Repeat the slow command with timing switched on. The profile output shows how long each stage took and how much memory it used, so you can tell a resolver problem from a download problem.

    composer install --profile
    composer diagnose
  2. 2Match what you see, then jump to its fix

    1. 1Composer prints a warning that Xdebug is enabled, and everything is slower than on a colleague's machine.Xdebug is loaded while Composer runsFix
    2. 2The deploy script or Dockerfile says composer update, and the slow step is the one before any download starts.Deploys run composer update instead of composer installFix
    3. 3The same packages download again on each CI run or container build, and the cache directory is empty or missing.The cache is switched off or thrown away on every runFix
    4. 4Installs are slow even when the network is fine, and your config or scripts ask for source.Packages are installed from source, by cloning git repositoriesFix
    5. 5Long pauses before each download, or a timeout message about getcomposer.org, while curl over IPv4 is fast.A broken IPv6 route delays every downloadFix

What does the error look like?

  • composer install runs for minutes and prints almost nothing
  • Failed to download * curl error 28 while downloading * Operation timed out after 300000 milliseconds
  • Operation too slow. Less than 1 bytes/sec transferred the last 30 seconds

Cause 1 of 5

Xdebug is loaded while Composer runs

1Check

Composer normally restarts PHP without Xdebug by itself. That restart is skipped when COMPOSER_ALLOW_XDEBUG is set to 1, for example in a shell profile, a Dockerfile or a CI job, and the warning also shows if the restart fails.

php -m | grep -i xdebug
printenv | grep -i COMPOSER_ALLOW_XDEBUG

2Fix

Remove the variable from wherever it is set. If you must keep Xdebug for other commands, leave it loaded and only unset the variable for Composer.

unset COMPOSER_ALLOW_XDEBUG
composer install

3Verify

The warning is gone and the run time drops.

composer install --profile

Confirmed by getcomposer.org

Did this fix it?

Cause 2 of 5

Deploys run composer update instead of composer install

1Check

When composer.lock exists, install reads the exact versions from it and does not resolve anything. Update resolves the dependencies from composer.json again and rewrites the lock file, which is the heavy step.

grep -rn "composer update" Dockerfile* deploy* .github .gitlab-ci.yml 2>/dev/null
git ls-files composer.lock

2Fix

Commit composer.lock and use install on servers and in CI. Run update only on a development machine, ideally for one package at a time.

composer install --no-dev
# on your machine, when you want newer versions of one package
composer update vendor/package

3Verify

The resolving phase disappears from the profile output.

composer install --no-dev --profile

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 5

The cache is switched off or thrown away on every run

1Check

Composer keeps downloaded archives in its cache directory. The --no-cache flag, or pointing COMPOSER_CACHE_DIR at /dev/null, disables that. A fresh CI runner also starts with an empty one.

composer config --list | grep -i cache
du -sh "$(composer config cache-dir)"

2Fix

Remove the flag or the variable, and tell your CI to keep the cache directory between runs.

# keep the cache in a folder your CI can store and restore
export COMPOSER_CACHE_DIR=/var/cache/composer
composer install

3Verify

A second run downloads nothing, and its profile shows a much shorter total.

composer install --profile

Confirmed by getcomposer.org

Did this fix it?

Cause 4 of 5

Packages are installed from source, by cloning git repositories

1Check

Composer downloads release archives by default, which is usually faster than cloning. Source installs happen with --prefer-source or when preferred-install is set to source.

composer config preferred-install
grep -rn "prefer-source\|prefer-install" . --include=*.json --include=*.sh --include=*.yml 2>/dev/null

2Fix

Go back to the archive installs, unless you really want a git checkout of a package you are developing.

{
    "config": {
        "preferred-install": "dist"
    }
}

3Verify

Run the install again and compare the time.

composer install --profile

Confirmed by getcomposer.org

Did this fix it?

Cause 5 of 5

A broken IPv6 route delays every download

1Check

If IPv6 is advertised but not routed, requests can hang until they time out. Compare the two address families against the URL Composer's troubleshooting page uses.

curl -4 -sS -o /dev/null -w "%{time_total}\n" https://getcomposer.org/version
curl -6 -sS -o /dev/null -w "%{time_total}\n" https://getcomposer.org/version

2Fix

Make Composer resolve names over IPv4 only. This works when the curl extension does the downloading. Fixing the IPv6 setup is the real cure.

COMPOSER_IPRESOLVE=4 composer install

3Verify

The pauses are gone from the run.

COMPOSER_IPRESOLVE=4 composer install --profile

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Keep COMPOSER_ALLOW_XDEBUG out of shell profiles, images and CI settings.
  • Install from the lock file on servers; make composer update a deliberate step on a dev machine.
  • Cache Composer's cache directory in CI, keyed on composer.lock.
  • Time the install in CI with --profile so a slowdown shows up in the log the day it begins.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require dies with 'Allowed memory size exhausted'

PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory'

Composer already lifts PHP's memory_limit to 1.5G on its own, so hitting this error means the job needs more than that, or the machine itself has too little memory.

4 causes, each with a fix

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.