Ok ! Finally after a week struggling with this issue :
First of all it seems to be a very popular problem for a century !
https://bugs.php.net/bug.php?id=11058
https://www.google.com/search?hl=es&ie=UTF-8&oe=UTF-8&q=php+php_network_getaddresses%3A+getaddrinfo+failed&meta=&gws_rd=ssl
Some ppl have found individual solutions at their own but definitely it's not a PHP bug .
What this issue can cover :
- If you can't connect with @fsockopen
- If can't get content with @file_get_contents
- If your php script can't send email or connect to SMTP Server
- If you can't ping your domain or getting can't find ping: Non-existent domain
- If you can't knock your server ip and getting getaddrinfo() failed
- If you have problem with php_network_getaddresses directly
- If your Wordpress throws error Unable to Connect to tcp://mydomain.com:80. Error #0: php_network_getaddresses: getaddrinfo failed: No such host is known.
--Things that can cause these problems-------------------------------------------------
[X]
First thing to check is to check your php.ini and make sure these attributes are enabled
allow_url_fopen = On
allow_url_include = On
[X]
Create a phpinfo() file [ phpinfofile.com just in case ] and check if these extensions are enabled
OpenSSL
Socket
Especially for windows user running xammp or wammp by disabling PHP_OpenSSL extension you might be unable to connect through @fsockopen
[X]
Now the important part, is to go after resolv.conf
Open your resolv.conf by running
sudo nano /etc/resolv.conf
- Delete comments, if there is a comment line at the start completely remove it
- Make a change to nameservers, even if they are fine just change the order of them, this helps to purge DNS cache if there's an old cache
[X]
Strongly make sure your /etc/resolv.conf is not a symlink pointing to some directories commonly at /run/resolvconf/ or etc ..
you can run
ls -la /etc/resolv.conf
and see what the result is, if it's something like
-rw-r----- 1 root root ` ` /etc/resolv.conf --------> /run/resolvconf/resolv.conf
If you have an ftp access go download your /etc/resolv.conf then rename the current one on your server to something line /etc/resolv.conf-----bk ( to have it just for backup ) and then upload the one you downloaded from your system to server /etc/
Or if you don't have access to ftp
run these commands
sudo cp /etc/resolv.conf /etc/resolv.conf.bak
sudo rm /etc/resolv.conf
sudo nano /etc/resolv.conf
put your nameservers on new file
ex:
nameserver 8.8.8.8
nameserver 8.8.4.4
and save it by pressing Ctr + X then Type "Y" and hit enter
chmod a+r /etc/resolv.conf
In this case my issue was that !
[X]
Make sure your reslv.conf is accessible to all users
chmod a+r /etc/resolv.conf
The result should be
-rw-r--r-- 1 root root <size> <date>
after running
ls -la /etc/resolv.conf
[X]
Next Run
sudo nano /etc/network/interfaces
Find the dns-nameservers and make sure nameservers seem fine ( preferably put whatever nameservers that are on your /etc/resolv.conf file - ex: dns-nameservers 8.8.8.8 8.8.4.4
That's all that i've discovered for this issue so far , i tried it to be understandable for anyone, sorry for annoying references to things you well know
If anybody else have something more for this matter please share it .