Forum Moderators: coopster

Message Too Old, No Replies

SimpleXML load file

         

webfoo

2:45 am on Sep 23, 2014 (gmt 0)

10+ Year Member



Hi All, it's been a while. I'm brushing the dust off my PHP.

I've got a PHP script that's supposed to ready a particular XML file, using this function:
$xml=simplexml_load_file('http://www.example.com/folder/feed.xml');


It doesn't work, and I get the following error:
Warning: simplexml_load_file(http://www.example.com/folder/feed.xml): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /home/user/public_html/file.php on line 363

Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://www.example.com/folder/feed.xml" in /home/user/public_html/file.php on line 363


The STRANGE part is that when I change the URL to other XML files, it works fine. It's just that one file that won't load. I've run the problem file through a validator with no problems reported, and I've manually validated it as well.

The EVEN STRANGER part is that I had this working on a dev server, but when I moved the application to the prod server, that's when the error started.

What am I doing wrong?

webfoo

9:54 pm on Sep 26, 2014 (gmt 0)

10+ Year Member



Bump.

Ocean10000

10:16 pm on Sep 26, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It could be they have blocked the IP address of your production server from being able to download that file or any file from that server.

Have you tried to download other files from that server on production machine? Did it have the same issue.

webfoo

12:55 am on Sep 27, 2014 (gmt 0)

10+ Year Member



Thanks for your reply!

AFAIK, there are not any other XML files on that server. But like I said, XML files from other sites work fine.

I even tried creating a new script for the express purpose of capturing the XML, just to make sure that was in fact the problem.

<?php
header('Content-Type: text/xml');
echo file_get_contents('http://www.example.com/folder/feed.xml');
?>


And I am greeted by this error message:
Warning: file_get_contents('http://www.example.com/folder/feed.xml'): failed to open stream: No such file or directory in <b>/home/user/public_html/file.php on line 2


The file does in fact exist, and I am able to load it from the dev server. What am I doing wrong?

Ocean10000

1:34 am on Sep 27, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



They could be blocking you from reading the file from your production server. Aka they check the IP which your server comes from against a known black listed ranges, and since it found in that range it returns a 404 message for it, instead of the proper data feed you were expecting.

Can you could contact the website in question and ask them if they are restricting access to this file?

omoutop

12:53 pm on Sep 29, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Since this works on your dev server, is there any possibility that allow_url_fopen is turned off on production server?

webfoo

1:14 pm on Sep 29, 2014 (gmt 0)

10+ Year Member



omoutop, that's what I thought at first, but I am able to access my own files as well as files from other domains, just not that one in particular.

Ocean10000, I think you are closer. Over the weekend, I sent an email to the host of the file I can't get, and another email to my hosting company. Hopefully between the two of them, someone will know what the hangup is.

omoutop

1:50 pm on Sep 29, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can you check your responce headers?
look at exampe at php manual: [php.net...]

function get_contents()
{
file_get_contents("your-url-here");
var_dump($http_response_header);
}
get_contents();
var_dump($http_response_header);

What do you get?