Solved

simplexml_load_file --> HTTP request problem

Posted on 2008-10-24
8
1,457 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

837 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