Olive
Olive

Reputation: 3516

fopen fails with getaddrinfo failed

I am having problems with the following code:

function http_file_exists($url){
$f=fopen($url,"r");
if($f){
    fclose($f);
    return true;
} else {
  return false;
}

} $url = "http://www.minhemmelighed.dk/Graphics/Products/55.jpg";

print http_file_exists($url);

The error it returns is:

Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /srv/http/webshop3/image_scraper/test.php on line 6 Warning: fopen(http://www.minhemmelighed.dk/Graphics/Products/55.jpg): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /srv/http/webshop3/image_scraper/test.php on line 6

What can I do about this? I have rebooted the server several times.

For the record:

I can access the website in question through a browser

I am running LAMP on Arch Linux

Upvotes: 4

Views: 9346

Answers (2)

Mark
Mark

Reputation: 194

For those of you running a very locked down distro like CentOS it is probably a security feature of SELinux as I discovered on my systems.

At the command prompt type:

getsebool -a | grep httpd

and look for

httpd_verify_dns --> off

if this is the case you will need to set it On with the following command

setsebool httpd_verify_dns=1

or permanently with:

setsebool -P httpd_verify_dns=1

remember to restart httpd with:

service httpd restart after every change

I hope that helps

Mark

Upvotes: 3

phihag
phihag

Reputation: 288220

Rebooting a UNIX server is extremely unlikely to fix a problem. It looks like you need to check your nameserver configuration on the server. On the console of the web server (logged in as the php user, probably apache or www-data), test

dig www.minhemmelighed.dk

If this outputs an error message, check your /etc/resolv.conf. Comment out all lines and add

nameserver 8.8.8.8 # Google's public DNS server

If that solves the problem, contact the administrator of the original nameserver (or just use Google's 8.8.8.8). If it doesn't, check your connectivity and firewalls.

Upvotes: 7

Related Questions