bobgreen5s Posted May 30, 2008 Share Posted May 30, 2008 Hello I have recently been using the php function, simplexml_load_file() in order to load an xml file and then display it. It was working perfectly until yesterday when it told me that my php server couldn't find the feed anymore. Here is the code and the resulting error message $xml = simplexml_load_file('http://feeds.feedburner.com/ace-bdf'); print_r($xml); Warning: simplexml_load_file(http://feeds.feedburner.com/ace-bdf) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\Program Files\XAMPP\xampp\htdocs\xampp\test\xmlfeed\index2.php on line 17 Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://feeds.feedburner.com/ace-bdf" in C:\Program Files\XAMPP\xampp\htdocs\xampp\test\xmlfeed\index2.php on line 17 This problem is extremely confusing because I can navigate to the feed (http://feeds.feedburner.com/ace-bdf) with my web browser without any problems. Also it was working perfectly a few days ago but stopped working even though I made zero modifications to the script. Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/ Share on other sites More sharing options...
bobgreen5s Posted May 30, 2008 Author Share Posted May 30, 2008 BUMP... any input would really be appreciated, I need to get this working Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-553897 Share on other sites More sharing options...
Barand Posted May 31, 2008 Share Posted May 31, 2008 When you go there with your browser, what file is being opened? Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-553961 Share on other sites More sharing options...
bobgreen5s Posted May 31, 2008 Author Share Posted May 31, 2008 Thank you for the reply, I think a xml file is opened Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554029 Share on other sites More sharing options...
Barand Posted May 31, 2008 Share Posted May 31, 2008 there is no xml file specified in your simplexml_load_file() call Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554104 Share on other sites More sharing options...
Prismatic Posted May 31, 2008 Share Posted May 31, 2008 I'm assuming the function actually requires an XML file, not a feed. To get around this load the feed into a string with file_get_contents and run simplexml_load_string on that Working code <?php print_r( simplexml_load_string( file_get_contents("http://feeds.feedburner.com/ace-bdf") ) ); ?> Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554119 Share on other sites More sharing options...
bobgreen5s Posted May 31, 2008 Author Share Posted May 31, 2008 Thanks for all the replies. When I try Prismatic's suggested code, <?php print_r( simplexml_load_string( file_get_contents("http://feeds.feedburner.com/ace-bdf") ) ); ?> This is this the resulting error message: Warning: file_get_contents(http://feeds.feedburner.com/ace-bdf) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\Program Files\XAMPP\xampp\htdocs\xampp\test\xmlfeed\index2.php on line 16 For some reason the php server doesn't think anything exists at the specified url. Its very strange because other feeds work and my feed worked up until a couple days ago. Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554309 Share on other sites More sharing options...
jonsjava Posted May 31, 2008 Share Posted May 31, 2008 your feed is there, and it's trying to call it, but unable to reach it. May be an issue with your hosting. Contact them, and see if they can reach that site from their servers (ask them to do a wget for that file on the same server you're hosted on. have them run this exact code: wget http://feeds.feedburner.com/ace-bdf Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554336 Share on other sites More sharing options...
bobgreen5s Posted May 31, 2008 Author Share Posted May 31, 2008 Well I thought the problem might be something on their server so I tried hosting my own server and it still didn't work. I tried wget on my own server and was successful. Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554354 Share on other sites More sharing options...
Prismatic Posted May 31, 2008 Share Posted May 31, 2008 They might possibly be looking at the HTTP Referrer and shutting out any new .php scripts, because the code I posted *was* working, now it's not. Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554357 Share on other sites More sharing options...
bobgreen5s Posted May 31, 2008 Author Share Posted May 31, 2008 I'm confused, are you saying that feedburner is rejecting the call from the script? Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554366 Share on other sites More sharing options...
Prismatic Posted May 31, 2008 Share Posted May 31, 2008 Actually when I attempt to grab the feed with CURL I get a 302 status code with a link directing me to -> http://feedproxy.feedburner.com/ace-bdf Though that's an invalid URL hmm Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554368 Share on other sites More sharing options...
Prismatic Posted May 31, 2008 Share Posted May 31, 2008 Here you go, requires CURL lib. Modified from: http://us.php.net/manual/en/ref.curl.php#78046 <?php $url = 'http://feeds.feedburner.com/ace-bdf'; function disguise_curl($url) { $curl = curl_init(); $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; // browsers keep this blank. curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)'); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com'); curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($curl, CURLOPT_AUTOREFERER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 10); $html = curl_exec($curl); curl_close($curl); return $html; } print_r( simplexml_load_string( disguise_curl($url) ) ); ?> Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554369 Share on other sites More sharing options...
bobgreen5s Posted May 31, 2008 Author Share Posted May 31, 2008 Wow thanks a lot, I'll have to install curl and give that a try Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554372 Share on other sites More sharing options...
bobgreen5s Posted May 31, 2008 Author Share Posted May 31, 2008 @Prismatic I tried your code and it works. Thats absolutely incredible, thanks again. Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554393 Share on other sites More sharing options...
Prismatic Posted May 31, 2008 Share Posted May 31, 2008 No problem Link to comment https://forums.phpfreaks.com/topic/108035-solved-problem-with-functionsimplexml-load-file/#findComment-554400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.