How to fix Composer’s slowness

You may have notice that Composer can get really, reaally slow on some setups. This is the case at my office, so I tried to find a solution. Let’s run Composer in very verbose mode :

# composer -vvv require phpunit/phpunit
Reading ./composer.json
Loading config file ./composer.json
Checking CA file /etc/ssl/certs/ca-certificates.crt
Writing /root/.composer/cache/repo/ into cache

And it seems to get stuck here. In fact, it’s not. If you wait for a little while (let’s say, 2 or 3 minutes), Composer stores the file in cache and downloads the next provider-*.json file. Which takes 3 more minutes and Composer won’t finish its downloads soon because, it will download more than 10 files after that.

But Google is great and it (he ?) gave me the solution :

# composer config --global repo.packagist composer

And now it runs fast. Just because sometimes, Packagist is slow through HTTP without SSL.

Please note : PHP must support SSL for this to work.