11

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 ?

code-8
  • 54,650
  • 106
  • 352
  • 604

15 Answers15

8

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!

garrettmills
  • 660
  • 6
  • 13
7

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...

The Billionaire Guy
  • 3,382
  • 28
  • 31
6

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-

zeus
  • 244
  • 3
  • 12
  • This worked for me, too. You can enable v6 again after running your composer commands: `networksetup -setv6automatic Wi-Fi` – Ti Hausmann Nov 26 '20 at 10:41
2

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.

Elisha Senoo
  • 3,489
  • 2
  • 22
  • 29
  • 1
    looks like they are using a firewall to block certain IPs. I used a VPN and it worked for me. – nh-labs Jan 31 '20 at 12:50
1

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.

online Thomas
  • 8,864
  • 6
  • 44
  • 85
1

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

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.

Ariful Islam
  • 696
  • 6
  • 11
0

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

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.

Gurpal singh
  • 1,511
  • 1
  • 14
  • 27
0

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

Especially if you're in China.

DevonDahon
  • 7,460
  • 6
  • 69
  • 114
0

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
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.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Deepak Dev
  • 101
  • 1
  • 7
0

Forcing the use of https with composer fix this. For anyone else who sees this, run the following to force composer to use https.

composer config -g repo.packagist composer https://packagist.org
Wesley-Sinde
  • 177
  • 3
  • 6
0

for me I tried to run composer install and got

Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.

so after I installed it

sudo apt-get install php-curl

and tried composer install it worked fine.

-1

Clearing the DNS cache fixed this for me.

In the terminal execute:

dscacheutil -flushcache

sudo killall -HUP mDNSResponder
Vincent
  • 54
  • 7