PHP and CURL

[email protected] ("Brian Artis") Sun, 24 Apr 2005 20:53:26 -0400
Newsgroups php.xml.dev
Organization Oval Sphere
Message-ID <[email protected]>
Recently my web host disabled PHP's allow_url_fopen.  This functionality 
allowed me to do the following:

if(!($handle = fopen('http://weather.gov/data/current_obs/KPHF.xml', "r")))
   echo ' ';

while($contents = fread($handle, 4096))
   xml_parse($xml_parser, $contents, feof($handle));

fclose($handle);

This allowed me to open the XML file and parse it with no problem using 
PHP's xml_parse functions.

As an alternative, they have installed CURL which is supposed to be very 
flexible.  However, I have
not been able to figure out how to open the XML file using CURL.  There are 
no samples that explain
what to do if your XML file is a URL.  The following code will not work.

$file = 'http://weather.gov/data/current_obs/KPHF.xml';

$curl_handle = curl_init();

curl_setopt ($curl_handle, CURLOPT_FILE, $file);  // opens file, but strips 
the xml tags

//curl_setopt($curl_handle, CURLOPT_URL, $file);  // produces an error

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);    // returns data as 
string

curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1);  // keeps page from 
hanging if site is down

$buffer = curl_exec($curl_handle);      // execute call
//print $buffer;
curl_close($curl_handle);

Anyone have any suggestions?
--