Is there any way deferring PHP code?
Like in javascript we use <script defer="defer"></script>. Is there any way to do the same with PHP-code?
UPDATE:
Here is the code I use:
Info: This code is located in my sidebar and causes the website to stop for 2-3 seconds when loading. I’m trying to skip this prosess and load this code when the rest of the site has loaded…. I’m open for other coding-solutions too.
<div style="padding:5px;">
<?php
function currency($from_Currency,$to_Currency,$amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode('"', $data['3']);
$var = $data['0'];
return round($var,1);
}
?>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 USD er <?php echo currency("USD","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 EUR er <?php echo currency("EUR","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 GBP er <?php echo currency("GBP","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 SEK er <?php echo currency("SEK","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 DKK er <?php echo currency("DKK","NOK",1); ?> NOK<br />
</div>
</div>
Two options:
Either way is fine, but if the data volume is large and/or the remote connection may be slow, then the cron option may be preferable.