Why is PHP Composer so slow?
Because Composer is implemented by file_get_contents()
. That has no TCP optimizations, no Keep-Alive, no multiplexing, etc.
I created a Composer plugin to download packages in parallel: https://packagist.org/packages/hirak/prestissimo
$ composer global require hirak/prestissimo
Please try it. In my environment, composer install
becomes 10 times faster.
The same here. Get more details with "composer install --profile -vvv". In my case it takes a long time to download a few JSON files. They get cached on my server, but they are still downloaded with every Composer update/install call.
... 30 minutes later ...
It looks like some performance problem @packagist.org. Now the Composer install runs within 2 seconds! And downloaded JSON files are properly cached.
Also, disable Xdebug. Xdebug can cause Composer to take minutes even when running a command as simple as composer --version
.
- Make sure you have the latest version of Composer.
- Install in verbose mode by adding -vvv, for example
composer global require "squizlabs/php_codesniffer=*" -vvv
- If you are able to find out where Composer is facing slowness, for example mine was getting stuck for 5 minutes when downloading packages. It took >5 minutes to download a 20 kB file on a 50 Mbit/s connection. This was because it was downloading the packages from packagist using HTTP and not HTTPS. Making these changes to the configuration has resolved my issue:
composer config --global repo.packagist composer https://packagist.org