Igor Simic
2 years ago

Composer error - packagist.org/packages.json file could not be downloaded: failed to open stream: Operation timed out


During installation of new dependencies using composer, if you are getting this error “https://packagist.org/packages.json” file could not be downloaded: failed to open stream: Operation timed out" here is what you have to do.

The problem could be that Mac OS is forcing IPV6 IP addresses and looks like packagist.org does not like that. So the workaround for this is to disable IPV6 force on your Mac. Here is how you can do it.

Open terminal and execute this command
networksetup -listallnetworkservices

you will get the list of network services, find your Wi-Fi from the list and stop IPV6 for it:
networksetup -setv6off Wi-Fi
after that you can run composer require your/package-name and it now it should work.

If you want to enable IPV6 again, execute this command
networksetup -setv6automatic Wi-Fi

If you have a same problem on Windows machine, the only way is to disable ipv6 entirely  (either in windows or in your home router).

More info about this problem can be found here  and other reasons for failing packagist connection can be found here