All pastes #738466 Raw Edit

Mine

public text v1 · immutable
·published 2007-10-16 10:45 UTC
rendered paste body
$cachefilename = "./elements/weather/weather/cache/$xml_url";

1 soluzione

    if (file_exists($cachefilename) && (time() - $ttl < filemtime($cachefilename))) {
        $url = $cachefilename;
        $curl_handle = curl_init($url);
        curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,10);
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        $xml = "";
        $xml = curl_exec($curl_handle);
        curl_close($curl_handle);
    }else{
        $url = $forecast_url;
        $curl_handle = curl_init($url);
        curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,10);
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        $xml = "";
        $xml = curl_exec($curl_handle);
        curl_close($curl_handle);
    }       

2 soluzione
	if (file_exists($cachefilename) && (time() - $ttl < filemtime($cachefilename))) {
	$url = $cachefilename;
	$fp = fopen($url,"r");
	while (!feof ($fp))
	$xml .= fgets($fp, 4096);
	fclose ($fp);
	}else{
	$url = $forecast_url;
	$fp = fopen($url,"r");
	while (!feof ($fp))
	$xml .= fgets($fp, 4096);
	fclose ($fp);
	$fw = fopen($cachefilename, 'w'); 
	fwrite($fw, $xml); 
	fclose($fw); 
	}