If composer hangs and you eventually see this error:
The "https://getcomposer.org/versions" file could not be downloaded: failed to open stream: Operation timed out
it could be a problem with IPv6 (for example if you’ve lost your IPv6 address for some reason.)
On MacOS you can turn IPv6 on and off via the command line. This:
networksetup -listallnetworkservices
…will give you a list of network interfaces (e.g. Ethernet, Wi-Fi, any VPNs)
networksetup -getinfo Wi-Fi
…will list all it’s settings; IP address, MAC and IPv6 status.
networksetup -setv6off Wi-Fi
…will turn IPv6 off. (To turn it back on, you’ll typically want -setv6automatic, though there’s also an option to set it manually.)
In my experience turning it off fixed the problem immediately, and composer worked straight away.
Obviously it’s preferable to fix your IPv6 and turn it back on, but this may be inconvenient if you have to reboot router etc. or beyond your control if there’s a problem with your ISP.
Useful page to test your IPv6 connection: http://ipv6test.google.com/
See also this GitHub issue
Tested with MacOS El Capitan 10.11.5