What to do if the composer require command takes too long to execute

Harish Toshniwal • July 10, 2018

original php miscellaneous

We all have been in the situation when the 'composer require' command takes too long to install a package. I found out a common problem I was facing and thought to share the solution for it.

I figured out the problem by using the "-vvv" flag with the 'composer require' command. Using the "-vvv" flag we can monitor what the command is actually doing and where it gets stuck. For me, it usually gets stuck while downloading the 'provider- * ' json files. I noticed that it downloads those files through packagist's non-secure url (http://packagist.com). I ran the following command to ask composer to use the secure (https) url for packagist:

composer config --global repo.packagist composer https://packagist.org

That solved the slowness of the composer require command for me. If you are aware of other possible & more better solutions, you can correct me with those on twitter.