I hava helper class and have functions:
static public function getPRBcurr(){
$currency = Cache::get('currency_prb_ee_agroTimeout');
if($currency) return $currency;
$contentCurrency = self::file_get_contents_curl(
'https://www.agroprombank.com/xmlinformer.php'
);
if(!$contentCurrency) {
$_currency = Storage::get('currency_prb_agro');
Cache::put('currency_prb_agroTimeout', $_currency, 60);
return $_currency;
}
$xmls = simplexml_load_string( $contentCurrency );
$currency = (string)$xmls->course[1]->currency[5]->currencySell;
$currency = ($currency > 0) ? $currency : null;
$currency = (strpos($currency, '1.0') !== false) ? '0.99' : $currency;
Cache::put('currency_prb_agroTimeout', $currency, 720);
Storage::put('currency_prb_agro', $currency);
return $currency;
}
static function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 500);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
And I have a product.blade:
<div class="price-prb">
<span itemprop="price">
@php
$prb = intval($product->price * Helper::getPRBcurr());
@endphp
{{ $prb }}
<span itemprop="priceCurrency" content="PRB"> {!! trans_choice('messages.currency.RUB', $prb) !!}</span>
</span>
</div>
When I go to category, where all products (890 products), page loading slow. If I remove Helper::getPRBcurr()
all is good. How I can fix this problem? Problem in function file_get_contents_curl 500ms timeout
.