composer install or composer update takes minutes instead of seconds
composer install runs for minutes and prints almost nothingShort 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.
Fix it fast
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 diagnose2Match what you see, then jump to its fix
- 1
Composer prints a warning that Xdebug is enabled, and everything is slower than on a colleague's machine.Xdebug is loaded while Composer runsFix - 2
The 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
The 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
Installs 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
Long pauses before each download, or a timeout message about getcomposer.org, while curl over IPv4 is fast.A broken IPv6 route delays every downloadFix
- 1
What does the error look like?
composer install runs for minutes and prints almost nothingFailed to download * curl error 28 while downloading * Operation timed out after 300000 millisecondsOperation 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_XDEBUG2Fix
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 install3Verify
The warning is gone and the run time drops.
composer install --profileConfirmed by getcomposer.org
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.lock2Fix
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/package3Verify
The resolving phase disappears from the profile output.
composer install --no-dev --profileConfirmed by getcomposer.org
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 install3Verify
A second run downloads nothing, and its profile shows a much shorter total.
composer install --profileConfirmed by getcomposer.org
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/null2Fix
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 --profileConfirmed by getcomposer.org
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/version2Fix
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 install3Verify
The pauses are gone from the run.
COMPOSER_IPRESOLVE=4 composer install --profileConfirmed by getcomposer.org
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 stops with curl error 28 while downloading packages
Operation timed out after 300000 milliseconds
Curl error 28 is a timeout.
3 causes, each with a fixBack 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 fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack 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