Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_get_contents - Connection timed out

Tags:

php

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

Why is the browser returning 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
like image 962
Bruno Avatar asked Nov 15 '10 23:11

Bruno


2 Answers

Mostly probably your server cannot connect to an external resource, for example, because of firewall restrictions.

like image 200
Hamish Avatar answered Oct 17 '22 22:10

Hamish


file_get_contents does not work well at all with getting remote files and should not be used. It does not deal with slow network connections or redirects, and does not return error codes. You should use curl instead to fetch remote files.

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

like image 34
Brent Baisley Avatar answered Oct 17 '22 22:10

Brent Baisley