Why is PHP Composer so slow when all I do is init a project with zero dependencies? Here are the commands I run:
composer init
On Ubuntu Xenial 16.04 VPS, you need to do the following:
sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
composer global require hirak/prestissimo
It configures IPv4 as preferred over IPv6.
https://serverfault.com/questions/93717/setting-ipv4-as-preferred-protocol-over-ipv6
composer global require "squizlabs/php_codesniffer=*" -vvv
composer config --global repo.packagist composer https://packagist.org
Mine was slow when downloading json files because of the antivirus. Some antiviruses scan all web traffic and it may be slow at analyzing json files. Try disabling your AV while running composer.
Also, disable Xdebug. Xdebug can cause Composer to take minutes even when running a command as simple as composer --version
.
In my case, the composer version i was running backdated. After updated the composer version itself the problem was gone.
To update the composer version run
composer self-update
and then require the composer package and you're done.
composer require "<package-name>"
If any of the previous answers don't work, check if your firewall allows for TCP_OUT on port 9418.
My firewall security was too sharp. This caused Composer to take so long, I never got any timeout or indication the port was blocked.