PHP валюта замедляет страницу

У меня есть страница с рекламой, и я устанавливаю валюту страницы в «RON», и я конвертирую, чтобы показывать также в «Euro», но в цикле очень медленно .. Я попытался включить скрипт из другого php, но все еще то же самое. … Я перепробовал много обменных пунктов, но у всех одна и та же проблема … замедлил страницу … и если я поместил код прямо в цикл, то я получил ошибку: класс не может быть повторен.
Вот валюта PHP, что я использовал:

<?php
class cursBnrXML
{

var $currency = array();

function cursBnrXML($url)
{
$this->xmlDocument = file_get_contents($url);
$this->parseXMLDocument();
}function parseXMLDocument()
{
$xml = new SimpleXMLElement($this->xmlDocument);

$this->date=$xml->Header->PublishingDate;

foreach($xml->Body->Cube->Rate as $line)
{
$this->currency[]=array("name"=>$line["currency"], "value"=>$line, "multiplier"=>$line["multiplier"]);
}
}
function getCurs($currency)
{
foreach($this->currency as $line)
{
if($line["name"]==$currency)
{
return $line["value"];
}
}

return "Incorrect currency!";
}
}
//@an example of using the cursBnrXML class
$curs=new cursBnrXML("http://www.bnr.ro/nbrfxrates.xml");
?>

-1

Решение

Вы можете изменить cursBnrXML класс для кэш проанализировал валюту, чтобы вам не приходилось повторять всю коллекцию снова при каждом поиске.

<?php
class cursBnrXML
{

private $_currency = array();

# keep the constructor the same# modify this method
function parseXMLDocument()
{
$xml = new SimpleXMLElement($this->xmlDocument);

$this->date=$xml->Header->PublishingDate;

foreach($xml->Body->Cube->Rate as $line)
{
$this->currency[$line["currency"]]=array(
"value"=>$line,
"multiplier"=>$line["multiplier"]
);
}
}

# modify this method too
function getCurs($currency)
{
if (isset($this->_currency[$currency]))
{
return $this->_currency[$currency]['value'];
}

return "Incorrect currency!";
}
}
//@an example of using the cursBnrXML class
$curs=new cursBnrXML("http://www.bnr.ro/nbrfxrates.xml");
?>
0

Другие решения

Других решений пока нет …