Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement exchange rate in PHP? [closed]

Tags:

php

How does major sites implement this?

Do they hardcode the rate or look it up each time?

like image 461
user198729 Avatar asked Nov 20 '25 09:11

user198729


1 Answers

An idea would be :

  • to call some external API regularly, to always have some fresh exchange rate (I don't know how often this can change -- but looking the rate up once every couple of minutes should do)
    • This could be done via some sort of cron job, independantly of your web-application that uses this exchange rate
  • and to keep the exchange rate in cache for a couple of minutes :
    • so you don't call the external API too often
    • and don't rely on it too much (i.e. your site will still work if the site you're fetching the rate from is down for a couple of minutes -- and if it takes time to fetch that data, it won't slow your website down, as it's fetched regularly by a cron job)
like image 98
Pascal MARTIN Avatar answered Nov 21 '25 23:11

Pascal MARTIN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!