I'm trying to implement google sign-in in my website that is written in Symfony2 using Google Client API. I followed the instructions here, but when I call $client->authenticate($code); command an exception is thrown telling that:
Failed to connect to www.googleapis.com port 443: Network unreachable
What is the problem?

- 1,521
- 2
- 15
- 21
-
check your firewalre configuration plesae see this http://stackoverflow.com/a/39590519/2652524 – Gujarat Santana Sep 20 '16 at 09:46
5 Answers
Solution 2 (from update). it seems to be some bug with ipv6 interfaces and curl with php, so another solution is to set the appropiate option in curl function to connect to the remote server with ipv4 in your php script
curl_setopt( $curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
Solution 1.
The same happened to me (solved by adding the ip v4 and hostname to /etc/hosts file), As pointed by @hans-z in another answer comment, I tried using next command to validate the network issue.
curl -v https://www.googleapis.com
It turned out that it was randomly, and only 1 in 10 tries the curl command could connect to the server, the response was something like: ("La red es inaccesible" means in english "network unreachable" :) )
$ 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
And the successfull response was:
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
The weird message was "Hostname was NOT found in DNS cache", I was using google DNS's 4.4.4.4 and 8.8.8.8, so I added that domain to my /etc/hosts file using the ipv4 from the curl command output and the problem was solved.
#/etc/hosts
...
64.233.186.95 www.googleapis.com
#DONT COPY THIS IP, USE THE ONE FROM YOUR CURL OUTPUT
...

- 2,488
- 24
- 31
-
This immediately resolved the timeout issues I was having while trying to connect to the **Google GCM API** from my local development - MAMP with Apache/2.2.29, PHP 5.6.10 and curl 7.41.0. What's weird is that not all requests were timing out. Many did though. Thanks for your help! – m_katsifarakis Dec 10 '15 at 02:54
Looks like an outgoing firewall/proxy/network issue. You should be able to verify that using ping
and curl
from the machine where your website runs.

- 50,496
- 12
- 102
- 115
-
-
1
-
Even when I type the url in my computer it brings a page with a string : Not Found. But there was no problem with my friends PC. – Reza Abbasi Feb 06 '15 at 18:47
-
When I type the url in browser most of the times it brings me Not Found and rarely it redirects to https://www.google.com/?gws_rd=ssl – Reza Abbasi Feb 06 '15 at 18:54
-
-
it happens to me too. from my local network sometimes (randomly) it resolves the host, using the curl command sometines y get: * 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 ... and sometimes error: connect to 2800:3f0:4003:c00::5f port 443 failed: The network is inaccessible * Failed to connect to www.googleapis.com port 443: The network is inaccessible * Closing connection 0 – le0diaz Apr 21 '15 at 21:34
-
to check if this is a firewall issue try `telnet android.googleapis.com 443` from your server.. – Hirdesh Vishwdewa Mar 05 '16 at 06:51
If your network under proxy. You should set the proxy url and port
curl_setopt($ch, CURLOPT_PROXY, "http://url.com"); //your proxy url
curl_setopt($ch, CURLOPT_PROXYPORT, "80"); // your proxy port number
This is solves my problem

- 193
- 1
- 7
Had the same issue - problem was with dns resolution, like mentioned in le0diaz's answer.
On ubuntu 16.04, we were able to solve it by chaning /etc/gai.conf, changing the presedance for IPv6, uncommenting the following line: precedence ::ffff:0:0/96 100

- 1
- 1