My goal is to run the below php script every 10 minutes and then be able to access the $temp
and $icon
values in a website front-end:
$api_endpoint = 'https://api.forecast.io/forecast/';
$api_key = get_field('forecast_api_key', 'option');
$latitude = get_field('latitude', 'option');
$longitude = get_field('longitude', 'option');
$units = 'auto';
$lang = 'en';
$exclude = 'minutely,hourly,daily,alerts,flags';
// Build API call and parse data
$url = $api_endpoint.$api_key.'/'.$latitude.','.$longitude.'?units='.$units.'&exclude='.$exclude;
$response = file_get_contents($url);
$weather_data = json_decode($response, true);
// Output to front-end
$temp = round($weather_data['currently']['temperature']);
$icon = $weather_data['currently']['icon'];
Could someone please explain on a high level what the best approach would be to do this? I need to limit the number of API calls per day to the endpoint and as far as I understand, this script should be executed as a cron task, but am not sure how to get at the variable values from a website in /var/www/
.
If I have overlooked a simpler way (i.e. not using cron) to limit the number of calls per period time, I would be interested in alternative suggestions too.
The server environment is an Ubuntu 14.04 LTS VPS.
Many thanks for your help.