Sometimes though, it's SO slow, which makes the site slow. Is there any way to make it the last thing to load? And also, if it takes too long, it's not loaded at all?
It also, sometimes, throws this up:
: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/kaexec/public_html/wp-content/themes/kaexec/header.php:87
Stack trace:
#0 /home/kaexec/public_html/wp-content/themes/kaexec/header.php(87): SimpleXMLElement->__construct('')
#1 /home/kaexec/public_html/wp-content/themes/kaexec/header.php(100): getWeather()
#2 /home/kaexec/public_html/wp-includes/theme.php(1115): require_once('/home/kaexec/pu...')
#3 /home/kaexec/public_html/wp-includes/theme.php(1091): load_template('/home/kaexec/pu...', true)
#4 /home/kaexec/public_html/wp-includes/general-template.php(34): locate_template(Array, true)
#5 /home/kaexec/public_html/wp-content/themes/kaexec/home.php(16): get_header()
#6 /home/kaexec/public_html/wp-includes/template-loader.php(43): include('/home/kaexec/pu...')
#7 /home/kaexec/public_html/wp-blog-header.php(16): require_once('/home/kaexec/pu...')
#8 /home/kaexec/public_html/index.php(17): require('/home/kaexec/pu...')
#9 {main}
thrown in /home/kaexec/public_html/wp-content/themes/kaexec/header.php on line 87This has only happened today. Line 87 is:
$xml = new SimplexmlElement($xml_str);
Thing is, when you make the API call in browser, it's instant: http://www.google.co...r=bn424nt&hl=en
So I don't know what to do...
Full code:
<?php
function getWeather() {
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://www.google.com/ig/api?weather=bn424nt&hl=en');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$xml_str = curl_exec($ch);
curl_close($ch);
$xml = new SimplexmlElement($xml_str);
$count = 0;
foreach($xml->weather as $item) {
foreach($item->current_conditions as $new) {
echo '<div class="weathericon">';
echo '<img src="http://www.google.com/' . $new->icon['data'] . '"/></div>';
echo '<div id="weather">';
echo round((($new->temp_f['data']* 1)-32) * (5 * 1) / (9 *1),1) . '°C<br>';
echo '<p>Forecast</p>' . $new->wind_condition['data'] . '</div>';
}
}
}
getWeather();
?>
This post has been edited by brightonmike: 06 February 2012 - 03:59 PM
Help


















