Solved

simplexml_load_file --> HTTP request problem

Posted on 2008-10-24
8
1,456 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

776 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