File_get_contents - Connection timeout

<?php
$a = file_get_contents('http://www.google.com');
echo $

Why does the browser return this error?

Warning: file_get_contents(http://www.google.com) [function.file-get-contents]: failed to open stream: Connection timed out in /home/test.php on line 2
+5
source share
4 answers

Most likely, your server cannot connect to an external resource, for example, due to firewall restrictions.

+3
source

I had the same problem, could not load using file_get_contents (), but using curl on the command line for the same URL worked fine. It turned out that he tried to connect via IPv6, which failed.

I solved this by disabling IPv6 in my kernel settings.

+2
source

file_get_contents . . curl , .

There curl_execis an example in the manual for : http://us3.php.net/manual/en/function.curl-exec.php

0
source

This may be a problem with the server, perhaps your server cannot communicate remotely with another server. You need to contact the server administrator.

0
source

All Articles