Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Cache yahoo weather and yahoo currency
Old 06-20-2010, 01:03 PM Cache yahoo weather and yahoo currency
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Hello to everyone!
I have a yahoo weather script and a yahoo currency script in my site but they are taking too much time to load and are slowing my site. Can someone help me to made them caching and refreshing cache every 3600 minutes?

yahoo weather
PHP Code:
<?php 
function retrieveYahooWeather($zipCode="92832") {
    
$yahooUrl "http://weather.yahooapis.com/forecastrss";
    
$yahooZip "?p=$zipCode";
    
$temp "&u=c"// Grade Celsius
    
$yahooFullUrl $yahooUrl $yahooZip $temp
    
$curlObject curl_init();
    
curl_setopt($curlObject,CURLOPT_URL,$yahooFullUrl);
    
curl_setopt($curlObject,CURLOPT_HEADER,false);
    
curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);
    
$returnYahooWeather curl_exec($curlObject);
    
curl_close($curlObject);
    return 
$returnYahooWeather;
}
$localZipCode "ALXX0002"// Tirane
$weatherXmlString retrieveYahooWeather($localZipCode);
$weatherXmlObject = new SimpleXMLElement($weatherXmlString);
$currentCondition $weatherXmlObject->xpath("//yweather:condition");
$currentTemperature $currentCondition[0]["temp"];// temperatura
$currentDescription $currentCondition[0]["text"];// teksti
$currentImage $currentCondition[0]["code"]; // kodi - perdoret per te marre fotografine/ikonen nga yahoo
$currentAstronomy$weatherXmlObject->xpath("//yweather:astronomy");
$currentSunrise $currentAstronomy[0]["sunrise"]; // lindja djellit
$currentSunset $currentAstronomy[0]["sunset"]; // perendimi djellit
$currentForecast $weatherXmlObject->xpath("//yweather:forecast");
$currentHigh $currentForecast[0]["high"]; // temp me e larte e dites
$currentLow $currentForecast[0]["low"]; // tem me e ulet e dites
?>
* P.S. How to change the time format from ex: 8:21 pm to 20:21?


yahoo currency
PHP Code:
// Funksionet per kembimin valutor

// Kembimi Euro - Leke
function kv_euro () {
$from   'EUR'/*change it to your required currencies */
$to     'ALL';
$url 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='$from $to .'=X';
$handle = @fopen($url'r');

if (
$handle) {
    
$result fgets($handle4096);
    
fclose($handle);
}
$allData explode(',',$result); /* Get all the contents to an array */
$kveuro $allData[1];
echo 
round($kveuro2); // round($dollarValue, 2); - Rrumbullakos shumebn me 2 shifra pas presjes. Ne gjendje normale $dollarValue
}

// Kembimi Dollare - Leke
function kv_dollare () {
$from   'USD'/*change it to your required currencies */
$to    'ALL';
$url 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='$from $to .'=X';
$handle2 = @fopen($url'r');

if (
$handle2) {
    
$result2 fgets($handle24096);
    
fclose($handle2);
}
$allData2 explode(',',$result2); /* Get all the contents to an array */
$kvdollare $allData2[1];
echo 
round($kvdollare2); // round($dollarValue, 2); - Rrumbullakos shumebn me 2 shifra pas presjes. Ne gjendje normale $dollarValue
}

// Kembimi Paund - Leke
function kv_gbp () {
$from   'GBP'/*change it to your required currencies */
$to    'ALL';
$url 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='$from $to .'=X';
$handle3 = @fopen($url'r');

if (
$handle3) {
    
$result3 fgets($handle34096);
    
fclose($handle3);
}
$allData3 explode(',',$result3); /* Get all the contents to an array */
$kvgbp $allData3[1];
echo 
round($kvgbp2); // round($dollarValue, 2); - Rrumbullakos shumebn me 2 shifra pas presjes. Ne gjendje normale $dollarValue

Hope that someone can help me! Thank you in advance!
Kleidi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-20-2010, 02:47 PM Re: Cache yahoo weather and yahoo currency
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use the same method but store the data in a local database.

When a visitor opens the page, display the local results from the data and at the same run the script to refresh the data.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-20-2010, 03:19 PM Re: Cache yahoo weather and yahoo currency
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Use the same method but store the data in a local database.

When a visitor opens the page, display the local results from the data and at the same run the script to refresh the data.
Thank you for your reply.
I'm new on php and i don't know how to do it Can you help me please?
Thanks again!
Kleidi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Cache yahoo weather and yahoo currency
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13018 seconds with 12 queries