File_Get_Contents(): PHP_Network_Getaddresses: Getaddrinfo Failed: Name or Service Not Known

PHP: file_get_contents() gives me Name or service not known

I hate to say this, but the problem solved itself; I just upgraded the Debian packages (apt-get upgrade) and the problem went away. Frustrating to not know the cause, though.

Thank you all for your time!

file_get_contents fails with getaddrinfo failed: no address associated with hostname

It seems that allow_url_fopen is disabled on you php.ini, that's why file_get_contents isn't working.

Try using curl instead:

$url = "http://www.example.com/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$page = curl_exec($ch);
curl_close($ch);
echo $page;

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name does not resolve

Did you run a short test.php inside the container too?

It is not a Symfony or PHP problem. In short container's network cannot resolve the IP address of the domain muckrock.com. Look for DNS settings for your container network. Tell more about your infrastructure. It is Kubernetes or something another?

For raw docker container running you can use something like this:

docker run -it --dns=8.8.8.8 php:7-fpm-alpine /bin/sh

Or for docker-compose something like this (or for version 3 as more actual)

version: 2
services:
application:
dns:
- 8.8.8.8

php_network_getaddresses: getaddrinfo failed: Name or service not known

If you only want to submit GET data to the URL, you should use something straightforward like file_get_contents();

$myGetData = "?var1=val1&var2=val2";
file_get_contents($url.$myGetData);


Related Topics



Leave a reply



Submit