PHP to fetch XML file into a string from external server


Wonder if someone can help. I am using the cURL function to fetch the XML file into a string from an external server. But I am not getting anything . If I took this ‘s0000450_e.xml’ file and stored it on my host server, the content is returned. My code is as follows…

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,’);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xmlContents = curl_exec($ch);

print("XML contents = “);



Black listed a Canadian Weather service!

I must admit that’s the last thing I would have thought of.

Thank all for your help. The problem is solved. It is not proxy server, my host server black listed the targeted IP.

The output is

text/x-generic AAA_20100616.dat
UTF-8 Unicode text, with CRLF, LF line terminators

X-Powered-By: PHP/5.2.13
Content-type: text/html

Error: couldn’t connect to host

Yeah, but if it was throwing a fatal (function undefined) error without error reporting, he’d get a BLANK screen, and his string echos wouldnt appear either, not to mention that he wouldnt have been able to cURL the local file.

Still, error reporting cant hurt.

if cURL wernt installed, wouldnt it be belching function_undefined errors?

phpinfo() shows that cURL is enabled as seen here
cURL support enabled
cURL Information libcurl/7.20.0 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5

Here is my a snippet of my code and var_dump output is in the attached text file. Can’t make out what the output mean…

$pageurl = “” . $province . “/” . $data_file;
print "
pageurl = ".$pageurl;

// Use cURL to fetch XML content into a PHP string variable.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pageurl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xmlContents = curl_exec($ch);

//$xmlContents = file_get_contents(‘’);


*********** displaying ch info *****************
************ End ****************

print("XML Contents = “);

Now that, would depend on the OPs error reporting/settings.

Normally, crmalibu would be the first to post the obligatory:-

ini_set('display_errors', true);

…snippet - and rightly so.

Here you go…

ini_set('display_errors', true);

if(false === function_exists('curl_init')){
  echo 'Error: curl extension not enabled/available';

$curl = curl_init('');

$xml = curl_exec($curl);

if(false === $xml){
  echo 'Error: ' . curl_error($curl);

echo $xml;

…and the output of this is?

khuant, could you add the output/code to a pastebin site (like pastie), the attachment needs to be manually approved so we can’t see it yet.

I just tried my above code and view-source shows

XML contents = <?xml version='1.0' encoding='ISO-8859-1'?>
 <siteData xmlns:xsi="" xsi:noNamespaceSchemaLocation="">
 <dateTime name="xmlCreation" zone="UTC" UTCOffset="0">
 <month name="June">06</month>
 <day name="Wednesday">16</day>

 <textSummary>Wednesday June 16, 2010 at 04:52 UTC</textSummary>

If you don’t have allow_url_fopen, are you sure you have cURL? i.e.


shows cURL?

No luck with file_get_contents()

What does var_dump(curl_getinfo($ch)) output?

I have not try file_get_content as I am not sure if their PHP is setup with allow_url_fopen set to true. But I will give it a try now.

Ah, so it looks like we maybe dealing with a proxy after all.

There are a few mentions of which servers to use on the interwebz, along with some accompanying code.

Raise a support ticket with GoDaddy or try a few of the solutions mentioned in the search above.

Good luck!


The file responsed fairly fast. You can try

Interestingly, I just looked godaddy’s policy on cURL up, and they removed the proxy requirement at the end of 2008 (but they’ve still got the servers running to accomodate legacy code)

khaunt, have you tried a standard file_get_contents on the URL?

Hmm… that is odd, as it should work the same… I suppose it’s possible that the server rejects connections that dont have a valid Agent code (Which is another CurlOpt), but i doubt it…

Is the server in question responding at a decent speed if you go to the file yourself? Is it slow?

Mittineague, I tried your code it didn’t work either. The content is blank.

Sorry Starlion I misunderstood your question. I don’t think my host uses a proxy as I was able to run the same code with another xml file from other server.

Any other suggestion?