Solved

simplexml_load_file --> HTTP request problem

Posted on 2008-10-24
8
1,461 Views
Last Modified: 2012-08-14
Hi,

I have a strange problem. I am using php to get data from a xml file.
It all worked, but suddenly it doesn't anymore. The XML url is correct.
Triple-checked the url.

Although the file used to work, when i made a copy of it and uploaded it, this error
also appeared. So my initial thought was that the (remote) server only allowed
this file to connect. My host has recently upgraded to php5.
BTW : allow_url_fopen = on.

Anyone with bright ideas? Thanks in advance.

I get  this error (replaced the urls with fake ones).:

Warning: simplexml_load_file(http://www.url.com/index.php?ID=2&ww=aaa&freq=all&land=world&actie=all) [function.simplexml-load-file]: failed to open stream: HTTP request failed! in /home/users/etc/file.php on line 42

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.url.com/index.php?ID=2&ww=aaa&freq=all&land=world&actie=all" in /home/users/etc/file.php on line 42

Warning: Invalid argument supplied for foreach() in /home/users/etc/file.php on line 43
0
Comment
Question by:dwax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 

Author Comment

by:dwax
ID: 22794934

Some more info: my ISP has  simplexml_load_file enabled.
Now i am thinking that the server where the XML is located has a user agent check of some sort,
if i acces the file via a browser it works, via .php it gives the error.

0
 
LVL 6

Expert Comment

by:fourice
ID: 22794942
Is it possible that due to the update the server doesn't allow a script to access the file (see the user_agent setting in php.ini).
Possible solution could be setting this manually:
user_agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
0
 
LVL 6

Expert Comment

by:fourice
ID: 22794957
You last reply wasn't there when I opened the thread. But we are thinking the same.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:dwax
ID: 22795041
Thanks fourice:

I was looking into setting the user agent in the php file that calls the XML,
but how do i implement this in .php?

Something like this?
header("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
0
 
LVL 6

Expert Comment

by:fourice
ID: 22795096
Try:
ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

0
 

Author Comment

by:dwax
ID: 22795355

Thanks, this:
header("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

Also seemed to do the trick, BUT:

i found out that if the XML is big, the 404 just comes back.
Could it be that the host is limiting the amount of data or something like that?
0
 
LVL 6

Accepted Solution

by:
fourice earned 250 total points
ID: 22798336
I doubt that a limit on the amount of data will give you a 404...
But just in case you could try adding:
ini_set("max_execution_time", 0);
ini_set("memory_limit", "10000M");
0
 

Author Comment

by:dwax
ID: 22948572
Whoopsidaisy, that does the trick!
Thanks fourice!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question