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);

Link to comment
Share on other sites

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);



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.