Why is PHP Composer so slow?

前端 未结 13 2007
攒了一身酷
攒了一身酷 2021-01-29 19:03

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

相关标签:
13条回答
  • 2021-01-29 19:31

    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

    0 讨论(0)
  • 2021-01-29 19:34
    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
    0 讨论(0)
  • 2021-01-29 19:37

    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.

    0 讨论(0)
  • 2021-01-29 19:38

    Also, disable Xdebug. Xdebug can cause Composer to take minutes even when running a command as simple as composer --version.

    0 讨论(0)
  • 2021-01-29 19:38

    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>"
    
    0 讨论(0)
  • 2021-01-29 19:40

    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.

    0 讨论(0)
提交回复
热议问题