在 Digital Ocean 上更新 Composer 时出现连接超时错误

Don*_*ash 1 composer-php digital-ocean ubuntu-16.04

我可以通过 ssh 进入我的 Droplet。我也能够 apt 更新和 apt 升级。

当我尝试运行 sudo composer self-update 或 composer update 时,出现连接超时错误。

The "https://getcomposer.org/versions" file could not be downloaded: failed to open stream: Connection timed out  
Run Code Online (Sandbox Code Playgroud)

输出 ufw status

To      Action    From
22      ALLOW     Anywhere
80      ALLOW     Anywhere
443     ALLOW     Anywhere
25      ALLOW     Anywhere
10000   ALLOW     Anywhere     
Run Code Online (Sandbox Code Playgroud)

输出 composer diagnose

Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: FAIL
[Composer\Downloader\TransportException] The "http://packagist.org/packages.json" file    could not be downloaded: failed to open stream: Connection timed out
Checking https connectivity to packagist: FAIL
[Composer\Downloader\TransportException] The "https://packagist.org/packages.json" file    could not be downloaded: failed to open stream: Connection timed out
Checking github.com rate limit: OK
Checking disk free space: OK
Checking composer version: 

[Composer\Downloader\TransportException]                                     
The "https://getcomposer.org/version" file could not be downloaded: failed   
to open stream: Connection timed out
Run Code Online (Sandbox Code Playgroud)

输出 composer --version

Composer version 1.0-dev (9e9c1917e1ed9f3f78b195a785aee3c6dc3cb883) 2015-11-23 10:31:23  
Run Code Online (Sandbox Code Playgroud)

输出 curl IL http://packagist.org/packages.json

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 10 Dec 2017 08:40:20 GMT
Content-Type: application/json
Content-Length: 1302
Last-Modified: Sun, 10 Dec 2017 08:38:28 GMT
Connection: keep-alive
ETag: "5a2cf284-516"
Cache-Control: private, max-age=0, no-cache
Accept-Ranges: bytes  
Run Code Online (Sandbox Code Playgroud)

我试图手动获取最新作曲家的副本,但它也不起作用

输出 php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

PHP Warning:  copy(https://getcomposer.org/installer): failed to open stream: Connection timed out in Command line code on line 1  
Run Code Online (Sandbox Code Playgroud)

可能是什么原因?我一直工作到大约一周前。我可以访问(浏览)我的 droplett 上托管的网页。我也能够 apt 更新和 apt 升级。

小智 6

您可以以 root 身份运行此命令以使 IPV4 比 IPV6 更优先:

sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
Run Code Online (Sandbox Code Playgroud)