9
votes

This morning, I ran this command

composer create-project laravel/laravel laravel-4.2 4.2 --prefer-dist

I kept getting

enter image description here

The "https://packagist.org/packages.json" file could not be downloaded: failed to open stream: Operation timed out
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info

Anyone know how to avoid this ?

13
the above error says that some problem with your composer version - Gaurav Gupta

13 Answers

7
votes

For me, this wasn't an issue with my internet connection speed, but it was a issue with IPv6 resolution of "repo.packagist.org". I got around this issue by adding the IPv4 address to my hosts file. It's a hack, but it works.

# dig +short repo.packagist.org
142.44.164.255
# echo "142.44.164.255 repo.packagist.org" >> /etc/hosts

More details here!

6
votes

try this solution worked for me!

"repositories": [
    {
         "type": "composer", 
         "url": "https://packagist.org"
    },
    { "packagist": false }
]

and run composer:update once again. If not then run composer self-update

I got the answer here and it works like voodoo...

6
votes

For me it was ipv6, I disabled it using: networksetup -setv6off Wi-Fi on macOS. Worked like a charm.

Solution found here: https://getcomposer.org/doc/articles/troubleshooting.md#operation-timed-out-ipv6-issues-

2
votes

The problem is most likely with your internet connect. Just try with another (or a more reliable) source of internet.

If problem persists, and you are sure of your internet connection, then checkout suggestions here.

1
votes

I have heard this problem can occur if you live in an area behind a government firewall, you might want to test if it works when behind a VPN.

1
votes

This question is similar to this: Installing laravel suddenly some json file cannot be downloaded

This is the answer that worked for me:

This worked on Linux. It prioritizes ipv4 over ipv6

sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
0
votes

This problem occurs for your low speed or bad connection. It failed to access internet and download repository. Check your internet connection and try again to connect your console to the internet.

0
votes

Mostly it happens when you did not get the response from the server. 1. check internet connection. 2. check any proxy block your response from the server. 3. if block proxy. When installing the composer that time you set proper proxy configuration on your installation process. 4. You should check your admin user privilege. 5. If you guest or limited account. You can not download any file from the outside server.

0
votes

The problem is due to slow internet connection or no internet. If there is no internet then The packages are unable to download from the server. that's why it gives this error i had face many time.

0
votes

Switch to a mirror according to your location : https://packagist.org/mirrors

Especially if you're in China.

0
votes

On linux, it seems that running this command helps to make ipv4 traffic have a higher prio than ipv6, which is a better alternative than disabling ipv6 entirely:

Workaround Linux:

sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"enter image description here

0
votes
export no_proxy=.github.com,.getcomposer.org

You can just add this code in your composer directory and hit enter. Then try again. While I was working on Magento 2 sample data deployment, I got the same error. This code did help me to continue the process.

-1
votes

Clearing the DNS cache fixed this for me.

In the terminal execute:

dscacheutil -flushcache

sudo killall -HUP mDNSResponder