如何在PHP中实现汇率? [英] How to implement exchange rate in PHP?

查看:192
本文介绍了如何在PHP中实现汇率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



他们是否硬编码率或每次查找?

解决方案

一个想法是:




  • 定期调用一些外部API,总是有一些新鲜汇率(我不知道这可以改变多久),但每隔几分钟就可以查看一次费用)


    • 这可以通过某种cron工作完成,独立于使用此汇率的网络应用程序


  • 将汇率保持在缓存中几分钟:


    • 所以你不要频繁调用外部API

    • ,不要太依赖它(例如,如果您提取速率的网站已经停了几分钟,您的网站仍然可以工作,如果需要时间来获取该数据,它不会减慢您的网站,因为它是由cron工作定期获取)



How does major sites implement this?

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

解决方案

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)

这篇关于如何在PHP中实现汇率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆