I'm trying to create a list of twitch.tv streams that pulls online/offline status every 60 seconds and returns an image based upon that response. The php code I'm using to pull this information and return the image is below:
<?php
header('content-type: image/png');
$stream = $_GET['stream'];
$json_file = @file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$stream}");
$json_array = json_decode($json_file, true);
if (strtolower($json_array[0]['name']) == strtolower("live_user_{$stream}")) {
echo file_get_contents("online.png");
}else{
echo file_get_contents("offline.png");
}
?>
This part works fine. I'm calling this code (image.php) like so:
<img src="image.php?stream=nameofstreamgoeshere" />
And it all works, but it's not live. I have tried several things to make it refresh and settled on jQuery likely being the best option. I think what I need to do is some combination of sending header information that forces browsers not to cache the image and perhaps place it into a div that jQuery refreshes every 60 seconds, but this is where I've hit brick walls. Any suggestions on how to do this? I'm relatively new to jQuery and am fumbling around a bit here, so any help would be much appreciated.
A lot of the potential solutions I've found for avoiding cached images include appending things to the image url like the date or time, but since this is already a dynamic image url I'm not sure how to make that work.
Thanks in advance for any help.