simplexml_load_file --> HTTP request problem


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( [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 "" in /home/users/etc/file.php on line 42

Warning: Invalid argument supplied for foreach() in /home/users/etc/file.php on line 43
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

fouriceConnect With a Mentor Commented:
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");
dwaxAuthor Commented:

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.

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)
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

You last reply wasn't there when I opened the thread. But we are thinking the same.
dwaxAuthor Commented:
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)");
ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

dwaxAuthor Commented:

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?
dwaxAuthor Commented:
Whoopsidaisy, that does the trick!
Thanks fourice!
All Courses

From novice to tech pro — start learning today.