-1

My Debian server has both IPV4 and IPV6 addresses.

I am using file_get_contents in my php script to get video titles from youtube:

if($content=file_get_contents("http://www.youtube.com/get_video_info?video_id=".$video_id)) {
}

Today I noticed that this script hangs for a long time and doesn't get any video titles.

Nginx logfile shows the following:

upstream timed out (110: Connection timed out) while reading response header from upstream.

I decided to make a test with wget:

    wget http://www.youtube.com/get_video_info?video_id=XX_hWpPnd3I
--2015-09-02 13:34:25--  http://www.youtube.com/get_video_info?video_id=XX_hWpPnd3I
Resolving www.youtube.com (www.youtube.com)... 2a00:1450:4007:80e::200e, 216.58.208.238
Connecting to www.youtube.com (www.youtube.com)|2a00:1450:4007:80e::200e|:80... failed: Connection timed out.
Connecting to www.youtube.com (www.youtube.com)|216.58.208.238|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-www-form-urlencoded]
Saving to: `get_video_info?video_id=XX_hWpPnd3I'

    [ <=>                                                                                                                                                        ] 400         --.-K/s   in 0s

2015-09-02 13:36:34 (42.9 MB/s) - `get_video_info?video_id=XX_hWpPnd3I' saved [400]

As you can see, the server is trying to use IPv6. When it does not work, it uses IPV4.

How can I fix this problem? phpinfo() says IPV6 is enabled. Why it doesn't work with file_get_contents and wget?

user1406271
  • 1,071
  • 4
  • 14
  • 20
  • -4, --inet4-only connect only to IPv4 addresses. –  Sep 02 '15 at 10:54
  • See also solution using `curl` at http://stackoverflow.com/a/11256153/2877364 – cxw Sep 02 '15 at 12:21
  • There are 2 steps to fix this issue. 1. Resolve the IPV6 connectivity issue (I.E Figure out why IPV6 does not work when you have an IPv6. may be you could check firewall rues). 2. as others have mentioned use IPV4 only to connect to the site (you could use a local resolver to do this). – vijay rajah Sep 02 '15 at 14:00
  • You need to test from more than one location on the internet before you can draw any conclusions. Pairwise connectivity tests between 3 or 4 different AS will give a much clearer picture. – kasperd Sep 02 '15 at 19:46

1 Answers1

1

It was a firewall problem. IPV6 was disabled in CSF.

user1406271
  • 1,071
  • 4
  • 14
  • 20