在 Digital Ocean 上更新作曲家时出现连接超时错误

Connection timeout error while updating composer on Digital Ocean

我可以通过 ssh 进入我的 Droplet。我也可以进行 apt update 和 apt upgrade。

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

The "https://getcomposer.org/versions" file could not be downloaded: failed to open stream: Connection timed out  

ufw status

的输出
To      Action    From
22      ALLOW     Anywhere
80      ALLOW     Anywhere
443     ALLOW     Anywhere
25      ALLOW     Anywhere
10000   ALLOW     Anywhere     

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

composer --version

的输出
Composer version 1.0-dev (9e9c1917e1ed9f3f78b195a785aee3c6dc3cb883) 2015-11-23 10:31:23  

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  

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

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  

可能是什么原因?直到大约一周前,我一直在工作。我能够访问(浏览)托管在我的 droplett 上的网页。我也可以进行 apt update 和 apt upgrade。

https://getcomposer.org/doc/articles/troubleshooting.md#operation-timed-out-ipv6-issues- 可以解决您的问题。如果之后 composer update 变慢,请尝试 运行 使用较新的 PHP 版本。 运行 它用 PHP 7 而不是 PHP 5 会导致很大的加速

您可以 运行 以 root 身份执行此命令,使 IPV4 优先于 IPV6:

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

关于这个超时,我也发现了上次执行composer命令的错误。 运行 "compose diag" 如果不是ipv6

然后重启命令解决问题

我的问题是由 PHP 7.2 引起的,切换回 PHP 7.1 后 'sphp 7.1',运行 再次执行命令 'composer update',它可以正常工作