Content
The symptom
When the Compose PHP we update a project with a package manager, the process is very slow, and it may even seem like the update has crashed.
So when we issue the following composer update command, for example:
composer update --with-dependencies
(In this example, I updated the base system for a copy of this Drupal-based page on my home server.)
Then the update starts, the first two lines are output:
Loading composer repositories with package information Updating dependencies (including require-dev)
But after that, nothing happens (apparently). Here, it usually takes about 1 minute for the dependencies to build up, but nothing happens after a long 10 minutes.
After a while, interrupting the process and then running the command again - vvv complete with debugging switch:
composer update -vvv --with-dependencies
Then we see more:
Here you can already see that the process is going in the background, just awfully slow. Downloading a Composer package from the repo takes several minutes. Thus, downloading a lot of packages and its dependencies can take up to many, many hours in total.
What is the solution then?
The solution
There was no problem with the previous update. So I thought about what circumstances might have changed since then, and only my internet service had changed. My new internet package now supports IPv6 IP addresses too. So in this direction I found the solution.
By default, the IPv6 address is not configured on the computers, so I had it on my home server as well. However, there are services that try to communicate first over IPv6, even if it is not already configured. This is also the case with Composer when you first try to connect to your repository over IPv6, but since it can't connect, after a while it drops the connection after a timeout, then switches to IPv4 and finally downloads the packet with it. Then when you download the next package, it all starts all over again. Thus, downloading lots and lots of packages together would take a lot of time.
So the solution is either to set up your IPv6 address properly or to migrate your system to make IPv4 our preferred network protocol. Since the first solution involves a separate topic, we now choose the latter here, which is an extremely simple solution. To do this, just open the /etc/gai.conf file to edit as root:
sudo nano /etc/gai.conf
And we add the following line to the end of the file as shown in the image below:
[...] precedence ::ffff:0:0/96 100
Or even use this command to easily add:
sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
The Composer will then update at normal speed via the IPv4 protocol.
Alternative solution
If this isn't exactly the problem, but let's say you can't access Composer's default repository, you can switch Composer to work from the English repository. To do this, issue the following command:
composer config repositories.packagist.org composer https://repo-eu-uk-1.packagist.org
This is used as a workaround until the main package is unavailable. To restore the default repository later, issue the following command:
composer config repositories.packagist.org --unset
Conclusion
For me, the first solution worked out, after prioritizing IPv4, the Composer update went well.
I hope this saves a little extra searching for those who might face just such an error.
- To post registration and login required
- 61 views