Why is PHP Composer so slow?

Solution 1:

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.

Solution 2:

  1. Make sure you have the latest version of Composer.
  2. Install in verbose mode by adding -vvv, for example composer global require "squizlabs/php_codesniffer=*" -vvv
  3. 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