$cache = '/tmp/imgoftheday.txt'; $nbsecondes = 3600; if (!file_exists($cache) || (filemtime($cache) <= (time() - $nbsecondes ))) { $json = json_decode(file_get_contents('http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US'), true); $res = 'http://www.bing.com'.$json['images'][0]['url']; file_put_contents($cache, $res); } else $res = file_get_contents($cache); echo $res;