I am using the file_get_contents function to get the URL into a string:
$contents = file_get_contents("http://google.com");
But, I am getting the following error:
file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: No such host is known.
How can I solve this in my localhost?
Your "localhost" cannot resolve the name google.com to an ip address, which means your machine doesn't/can't reach a valid dns server.
This probably doesn't only affect php. Try ping google.com on the console of that machine. Does this complain about the unknown host, too?
The steps necessary to solve the problem depend on what your "localhost" is (operating system, flavour/distribution, ...) and how it is connected to the internet.
It is because you need to turn on allow_url_fopen in php.ini
Check your localhost and username.
Like if you are using Xampp, in the host column type Localhost
and the database name
and last but not least the username with root, and then install.
It's quite easy but if you missing it, it's gone be very upsetting.
Related
I am setting my ubuntu web server up and I am setting up a firewall on it. All is good except for my one document that has file_get_contents() up. I am just wondering what port i need to unblock for this to work.
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/site/videos.php on line 65
That is the warning I get from the file. Im sure it's a port issue because if there all unblocked, it works just fine. Any help would be great!
Code for file_get:
$xml = simplexml_load_string(file_get_contents('http://gdata.youtube.com/feeds/api/users/TomSka/uploads'));
To change the firewall setting as detailed in the link and it will works. Please refer below document
http://www.radiotope.com/content/safari-and-sonicwall
The setting was "Enforce Host Tag Search with for CFS"
Weirldly it only seems to affect fgets on PHP 5 running on Linux other platforms and other PHP generated HTTP requests are unaffected.
I'm trying to follow this tutorial:
http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/
But, for love nor money, I couldn't get a response out of the console.
I loaded up the startDeamon manually and found it was failing to bind to my (local) host.
Warning: socket_bind() [function.socket-bind]: Host lookup failed [-10001]: Unknown host
My local server is running on http://localhost:33. I have specifying my host as both localhost and 127.0.0.1, with and without http, and with and without specifying the port, but no joy.
Can anyone help me out?
Thanks in advance
Try using port 12345 instead of 33.
remove the http:// part and just try access it as localhost
you cannot use localhost, or 127.0.0.1 when dealing with sockets, but need to use the domain/host name or host IP address instead. It is explained as a user experience in the PHP5 manual section
I have a blog on tumblr, and I'm trying to access it via php and tumblrs api.
the api endpoint is:
http://blog.example.com/api/read/json?start=0&num=10&debug=1
and that seems to work fine.
However, when I do:
$result = file_get_contents("http://blog.example.com/api/read/json?start=0&num=10&debug=1");
print_r($result);
the browser outputs
Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to/file/test.php on line 5
Warning: file_get_contents(http://blog.example.com/api/read/json?start=0&num=10&debug=1) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to/file/test.php on line 5
This also fails with Curl.
Ideas?
I think this has something to do with the fact that my blog is on a subdomain. The reason I say this, is, if I run the same script on a blog located on the root url, it works fine. Is there a correct way to escape subdomains?
This code is failing because the DNS lookup is failing. This could be because your server is having trouble contacting its name servers. Or its because blog.example.com doesn't exist (it fails in my browser so it should fail everywhere). You could try changing your name servers to google's: 8.8.8.8 and 8.8.4.4. These DNS servers work well.
New Tumblr API: http://www.tumblr.com/docs/en/api/v2
If you have your domain with your tumblr account it will work. An example
I got the following error when I get contents from file("http://www.otherdomain.com").
file() [function.file]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
The domain server is linux.
How to resolve this problem?
Quoting:
If you're having problems with fopen("url...") but you can run 'host
url' in a shell window and get the
correct lookup, here's why...
This has had me banging my head
against it all day - finally I found
the answer buried in the bug reports,
but figured it should really be more
prominent!
The problem happens when you're on an
ADSL line with DHCP (like our
office)... When the ADSL modem renews
the DHCP lease, you can also switch
DNS servers, which confuses apache
(and hence PHP) - meaning that you
can't look up hosts from within PHP,
even though you can from the
commandline.... The short-term
solution is to restart apache.
You'll get "php_network_getaddresses:
getaddrinfo failed: Temporary failure
in name resolution in ..." messages as
symptoms. Restart apache, and they're
gone :-)
Simon
Comment by Simon at php.net
make sure that website can be reached from you server.
also make sure that you are using has a proper DNS server setup.
if you are sure that website is working ... try modifying the /etc/hosts file and add the website's IP for test purposes, then try to figure out why it doesn't solve the domain.
The Domain can not be resolved to it's IP address.
If you have your DNS running local, try restarting it. If not, check your DNS or add a different server to /etc/resolve.conf (i.e. nameserver 8.8.8.8).
You can also add the domain as a static entry in your hosts file:
On your linux server add the DNS information to your /etc/hosts file using:
echo '127.0.0.1 www.otherdomain.com' >> /etc/hosts
…where 127.0.0.1 is the IP address of your website and www.otherdomain.com the domain name your using.
You can find the IP address of any domain using nslookup, i.e
nslookup www.otherdomain.com
I was running into this issue with CiviCRM geocoding! Restarting Apache like Shehi recommended fixed the problem.
check your internet connection. If the internet is down, this error occurs.
Sample code:
$html = file_get_contents('http://www.google.com');
echo $html;
It works on localhost. But after uploading to the webserver, it gives me a warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution. If I replace the domain name with google's IP address, it gives a warning: failed to open stream: Connection timed out.
And ini_get("allow_url_fopen") return 1.
===
Edit: Probably it is a server problem. I guess this question should be asked on serverfault.com.
Your host is most likely refusing the outbound connection. It's the only thing I can think of.
This is a known bug in some versions of PHP. Tell your host about the problem and ask them to upgrade PHP.
It's also possible that your host have extremely naive firewall rules in place blocking just about any networking you try to do. Which host is it?