I have a currency widget that updates currency rates every minute or so. For a number of reasons i would prefer to have just one or two updates daily.
is it possible to create an automatic database that updates the latest rate at a certain time daily, so that my page could then get the rate from MY database rather than querying the API?
question: what currency rate are you interested in? because the official exchange rate is set only once a (work) day. then it would suffice to run the API call at that time.
that’s correct, but there is only one official end-of-the-day exchange rate. for example, if you‘re looking for the exchange rate USD-EUR on 20-05-2015, there will only be one value (1.1118).
that’s what cronjobs are for. execute a script at predefined times (resp. intervals).
create a database at the server
create a cron file (but if it is to reside in the server, why the question of whether my PC runs on Windows? It does)
have a script (php?) to downloasd the data from the Api
access the data from the webpage
Maybe what I call psuedo-cron would be good enough?
That is, if your site has enough traffic you can have the job run the first page load after an arbitrary time.
Pros - no real cron used
Cons - whoever triggers that job may get slower load times
the run time is not as precise
Right now I’m trying to work out what is involved and your idea is very interesting.
It looks as if my first problem is to get a script to download the data to a database in the server. That should be very interesting as I know ABSOLUTELY NOTHING about php…
Nothing. In fact that would be the preferred way.
If your host lets you do cron jobs IMHO that is how you should do it.
No matter how the script is initiated, you will need that.
I’d start with thinking about what information is available and what you might need to have in the database. i.e. the database schema
I’m talking about over 100 currencies, and starting to think if this makes sense. I already have a widget with that information that is updated EVERY TIME the page is opened. One of the reasons (there are others) for doing this database business is to get rid of a script in the page. But… in order for the widget, in future, to gather the necessary information in respect of a pair of currencies, I am starting to think that another script is needed.
I thought originally that the rates could be got directly from the database, but even if it is a page that deals with exchange between GBP and EUR, there is a drop-down list that allows any combination of over 100 currencies.