Jump to content

retrieve xm; file using file_get_contents($request); too slow with unicode


sdowney1

Recommended Posts

I am trying to retrieve an xml file from a webservice.

I cant use the original server since it gags on non latin characters, unicode?, that is what the LOC says.

 

The other server does work with non latin characters

BUT it is too slow with file_get_contents, takes a minute to get anything, so slow you cant even use it in the program.

YET, retrieves the xml fast in the browser window.

 

So, what can I do that will work fast like it should?


//original database server, file_get_contents is faster, about 3 to 10 seconds
//$request= 'http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve'.$query.$test2.'&startRecord='.$offset.'&maximumRecords=20';

//new one that can handle non latin characters  
//file_get_contents is SLOW, so slow to be unusable, about a minute or more
$request='http://lx2.loc.gov:210/LCDB?version=1.1&operation=searchRetrieve'.$query.$test2.'&startRecord='.$offset.'&maximumRecords=20';


   $raw_xml = file_get_contents($request);
   $filename = dirname(__FILE__)."/loc.xml";
   $fp = fopen($filename, "w");
   fwrite($fp, $raw_xml);
   fclose ($fp);

this is working much better with cURL, it has to be on, installed to work.

XML file retrieved very quickly now.

 

for ubuntu

sudo apt-get install php5-curl

sudo /etc/init.d/apache2 restart

 

//http://ar2.php.net/manual/es/function.file-get-contents.php#82255
$url = curl_get_file_contents($request);

function curl_get_file_contents($URL)
    {
        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $URL);
        $contents = curl_exec($c);
        curl_close($c);

        if ($contents) return $contents;
            else return FALSE;
    }

   $filename = dirname(__FILE__)."/loc.xml";
  //echo $raw_xml;
   $fp = fopen($filename, "w");
   fwrite($fp, $url);
   fclose ($fp);



Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.