2015-02-06 3143 views

回答

3

看起来像一个传出的防火墙/代理/网络问题。您应该能够验证在您的网站运行的机器上使用pingcurl

+0

我在本地主机上测试它。这是问题吗? – 2015-02-06 16:03:50

+1

尝试'curl -v https:// www.googleapis.com'并查看它报告的内容 – 2015-02-06 17:06:38

+1

我尝试使用我的VPS并打印404 Not Found响应。 – 2015-02-06 18:43:11

6

解决方案2(来自更新)。 它似乎是与IPv6接口的一些bug,并使用PHP卷曲,所以另一种解决方案是设置在卷曲功能此时,相应的选项,使用IPv4连接到远程服务器在你的PHP脚本

curl_setopt($卷曲,CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);


解决方法1.

同样的事情发生在我(通过将IP v4和主机名解决了/ etc/hosts文件),作为另一个答案评论指出通过@汉斯-Z,我尝试使用下一个命令来验证网络问题。

原来,这是随机的,只有在10名试图1 curl命令可以连接到服务器,该反应是这样的: (“拉红色ES inaccesible”在英语中的“网络不可达指“:))

$ curl -v https://www.googleapis.com 
* Rebuilt URL to: https://www.googleapis.com/ 
* Hostname was NOT found in DNS cache 
* Trying 64.233.186.95... 
* Trying 2800:3f0:4003:c00::5f... 
* connect to 2800:3f0:4003:c00::5f port 443 failed: La red es inaccesible 
* Failed to connect to www.googleapis.com port 443: La red es inaccesible 
* Closing connection 0 
curl: (7) Failed to connect to www.googleapis.com port 443: La red es inaccesible 

而且全成反应是:

curl -v https://www.googleapis.com 
* Rebuilt URL to: https://www.googleapis.com/ 
* Hostname was NOT found in DNS cache 
* Trying 64.233.186.95... 
* Trying 2800:3f0:4003:c00::5f... 
* Connected to www.googleapis.com (64.233.186.95) port 443 (#0) 
* successfully set certificate verify locations: 
* CAfile: none 
    CApath: /etc/ssl/certs 
* SSLv3, TLS handshake, Client hello (1): 
* SSLv3, TLS handshake, Server hello (2): 
* SSLv3, TLS handshake, CERT (11): 
* SSLv3, TLS handshake, Server key exchange (12): 
* SSLv3, TLS handshake, Server finished (14): 
* SSLv3, TLS handshake, Client key exchange (16): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256 
* Server certificate: 
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.storage.googleapis.com 
* start date: 2015-04-08 14:12:01 GMT 
* expire date: 2015-07-07 00:00:00 GMT 
* subjectAltName: www.googleapis.com matched 
* issuer: C=US; O=Google Inc; CN=Google Internet Authority G2 
* SSL certificate verify ok. 
> GET/HTTP/1.1 
> User-Agent: curl/7.35.0 
> Host: www.googleapis.com 
> Accept: */* 
> 
< HTTP/1.1 404 Not Found 
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
< Pragma: no-cache 
< Expires: Fri, 01 Jan 1990 00:00:00 GMT 
< Date: Tue, 21 Apr 2015 21:38:12 GMT 
< Vary: X-Origin 
< Content-Type: text/html; charset=UTF-8 
< X-Content-Type-Options: nosniff 
< X-Frame-Options: SAMEORIGIN 
< X-XSS-Protection: 1; mode=block 
* Server GSE is not blacklisted 
< Server: GSE 
< Alternate-Protocol: 443:quic,p=1 
< Accept-Ranges: none 
< Vary: Origin,Accept-Encoding 
< Transfer-Encoding: chunked 
< 
* Connection #0 to host www.googleapis.com left intact 

是怪异的消息‘主机名未在DNS高速缓存中找到’我使用谷歌DNS的4.4。 4.4和8.8.8.8,所以我使用curl命令输出中的ipv4将该域添加到我的/ etc/hosts文件中,问题已解决。

#/etc/hosts 
... 
64.233.186.95 www.googleapis.com 
#DONT COPY THIS IP, USE THE ONE FROM YOUR CURL OUTPUT 
... 
+0

这立即解决了我尝试连接到** Google GCM API **时遇到的超时问题我的本地开发 - MAMP与Apache/2.2.29,PHP 5.6.10和curl 7.41.0。 奇怪的是,并非所有请求都超时。许多人虽然。 感谢您的帮助! – 2015-12-10 02:54:26

2

如果在代理网络。你应该设置代理地址和端口

curl_setopt($ch, CURLOPT_PROXY, "http://url.com"); //your proxy url 
curl_setopt($ch, CURLOPT_PROXYPORT, "80"); // your proxy port number 

这是解决我的问题

1

试试这个回声的IPv4 >>〜/ .curlrc。 它为我工作。

+0

这应该是一个评论,而不是一个答案! – 2017-06-16 10:26:33

+0

对不起Div我无法评论这就是为什么我回答 – 2017-06-19 12:28:00

0

有同样的问题 - 问题是与DNS解决问题,就像在le0diaz的答案中提到的。

在Ubuntu 16.04中,我们能够通过chaning /etc/gai.conf,改变对IPv6的presedance,取消注释以下行来解决这个问题: 优先:: FFFF:0:0/96 100

相关问题