My shopping app needs to do currency conversion, my plan is to use a crontab to grab the latest exchange rates once an hour. My question is whats the best way to store and use this in my CI application. Should I:
– Write it to the DB everytime its run and then grab the rate from the DB evrytime i need to do a conversion
– Do the same but with a text file
– Write it to a constant in the index.php
– Some sort of core or hook file
Whats the most efficient way
The quick & dirty way would be writing a PHP file with the said currencies. You can use
var_export()to save them safely.Config:
Cronjob:
Currency Page:
Note that we don’t even connect to DB anywhere, making this very fast. There is also no parsing/conversion. With the DB concept, you have to at least loop over the database rows. Using a normal config medium, such as ini, json or xml files would requiring some form of parsing after PHP loads. Whereas, with this method, it is a part of PHP’s loading process; you’re just including a small PHP file.