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?