Caching fixer.io free account with PHP and cron job.
Free account is limited to 1000 requests per month, hourly data and only EUR as base currency. In my case, I'm fine with hourly and base currency limitation, but probably not ok with the monthly requests limit. To avoid exceeding that, rather than my front-end app requesting directly to fixer.io, it's better for me to set an hourly cron job to do the request to fixer.io and store it on my own server.
1 request * 24 hours * 31 days = 744 requests/month. Well below the monthly limit.
- Create fixer.io account
- Put API key to file named
apikey
onprivate
directory. - Set cron job to run
private/create_cache.php
every hour. GET cache.json
to read the cache.
- Make sure to prevent public access to
private
folder (to protect theapikey
and prevent public from making request to fixer.io by callingcreate_cache.php
). You can use something like.htaccess
:Deny from all
private/apikey
is already on.gitignore
to prevent leaking that via repo.