Welcome to WebmasterWorld Guest from 54.91.71.108

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

SimpleXML load file

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

Full Member from US 

10+ Year Member

joined:Mar 22, 2008
posts: 319
votes: 0


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?
9:54 pm on Sept 26, 2014 (gmt 0)

Full Member from US 

10+ Year Member

joined:Mar 22, 2008
posts: 319
votes: 0


Bump.
10:16 pm on Sept 26, 2014 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


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.
12:55 am on Sept 27, 2014 (gmt 0)

Full Member from US 

10+ Year Member

joined:Mar 22, 2008
posts: 319
votes: 0


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?
1:34 am on Sept 27, 2014 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


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?
12:53 pm on Sept 29, 2014 (gmt 0)

Senior Member

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

joined:Oct 15, 2004
posts:942
votes: 0


Since this works on your dev server, is there any possibility that allow_url_fopen is turned off on production server?
1:14 pm on Sept 29, 2014 (gmt 0)

Full Member from US 

10+ Year Member

joined:Mar 22, 2008
posts: 319
votes: 0


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.
1:50 pm on Sept 29, 2014 (gmt 0)

Senior Member

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

joined:Oct 15, 2004
posts:942
votes: 0


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?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members