|
[Edit] Yahoo Weather With Cache System
define(CACHE_DIR, 'cache');
define(CACHE_AGE, 3600);
function retrieve($zipCode="92832") {
$path = CACHE_DIR . '/cache.xml';
$cached = get_cache_value($path);
if(false !== $cached){
$result = $cached;
} else {
$url = "http://weather.yahooapis.com/forecastrss?p=$zipCode&u=c";
$result = file_get_contents($url);
set_cache_value($path, $result);
}
$XmlObject = new SimpleXMLElement($result);
return array('location' => $XmlObject->xpath('//yweather:location') ,'forecast' => $XmlObject->xpath('//yweather:forecast'));
}
function get_cache_value($path){
if(file_exists($path)){
$now = time();
$file_age = filemtime($path);
if(($now - $file_age) < CACHE_AGE){
return file_get_contents($path);
} else {
return false;
}
} else {
return false;
}
}
function set_cache_value($path, $value){
return file_put_contents($path, $value);
}
|
This Page is Under Construction! - If You Want To Help Please Send your CV - Advanced Web Core (BETA)
© Advanced Web Core. All rights reserved

