simplexml_load_file just stopped working - php

I read a blog into my website using somehting like this...
define('BLOG_PATH', 'http://kvfcblog.blogspot.co.uk/feeds/posts/default');
$url = BLOG_PATH . "?alt=rss&category=" . $page;
$xml = simplexml_load_file($url);
where $page = index, so reading from
http://kvfcblog.blogspot.co.uk/feeds/posts/default?alt=rss&category=index
this works fine on my localhost, and used to work just as well on my live site, until today, when I started getting these errors ...
simplexml_load_file(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/shdpbmib/public_html/rss/kvfc_rss.php on line 17
simplexml_load_file(http://kvfcblog.blogspot.co.uk/feeds/posts/default?alt=rss&category=index): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/shdpbmib/public_html/rss/kvfc_rss.php on line 17
simplexml_load_file(): I/O warning : failed to load external entity "http://kvfcblog.blogspot.co.uk/feeds/posts/default?alt=rss&category=index" in /home/shdpbmib/public_html/rss/kvfc_rss.php on line 17
Strangley, it still works fine from my localhost
Any ideas? I tried rawurlencode(), but that didn't make any difference

I see that this is getting pretty old but... can you ping the address you're trying to reach? Or can you reach it any other way?
ping your_server_ip
ping stackoverflow.com
If pinging fails, that means something's wrong with your server. It looks like the hostname you're passing to run can't be resolved. You can try:
import socket
socket.getaddrinfo('localhost', 8080)

Related

Ubuntu iptable messing file_get_contents() up

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.

Magento API access on localhost without using internet connection

I have installation of magento 1.6.1 on local machine i\’m trying to connect magetno\’s api in php using following code
$proxy = new SoapClient('http://localhost/magento/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiuser', 'apikey');
I can connect using this code if internet connection on, If I make it off it doesn't work.
it gives following errors
Warning: SoapClient::SoapClient() [soapclient.soapclient]: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\wamp\www\magentomanager\api\products.php on line 12
Warning: SoapClient::SoapClient(http://schemas.xmlsoap.org/soap/encoding/) [soapclient.soapclient]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\wamp\www\magentomanager\api\products.php on line 12
please let me know what is the reason behind that?.
why magento needed internet connection for accessing local api. how do I access api without having without internet connection?
Magento's API is based on SOAP, as you may have found out. SOAP is based on XML and uses therefor schema files, which desribes the schema/layout for the SOAP calls for this service. So this file might be loaded before/on every SOAP call.
However, a workaorund could be to store the schema description on your local machine and editing Magento's wsdl.xml files, so that they will reference to your local machine. Simply search for the URL in all xml files inside your Magento installation.
Not a very nice workaround, but hey,... it's a workaround.
I think the problem is that localhost can't be resolved to your local IP or 127.0.0.1. You can add it in your host file or call it thru http:/// instead of http://localhost

file_get_contents failing

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

PHP file_get_contents() does not work after uploading to the webserver

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?

file_get_contents(): No such host is known error

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.

Categories