Answer the question
In order to leave comments, you need to log in
Why can the parser go wrong?
I assembled a simple weather parser from Yandex, but there was such a problem:
As you can see, it shows, then it doesn’t. Question because of what there can be such trabl? ;(
<?php
$city_id = 35229;
$data_file = "http://export.yandex.ru/weather-ng/forecasts/$city_id.xml";
$xml = simplexml_load_file($data_file);
$city = $xml->fact->station;
$temp = $xml->fact->temperature;
$pic = $xml->fact->{'image-v3'};
$type = $xml->fact->weather_type;
if ($temp > 0) {
$temp = '+' . $temp;
}
echo ("Актобе");
echo (" $temp °C <img src=\"https://yandex.st/weather/v-1/i/icons/30x30/$pic.png\" alt=\"$type\" title=\"$type\">");
?>
Answer the question
In order to leave comments, you need to log in
Ilya says the point, update the xml once a minute and parse the file, not the url, otherwise you will shoot at sparrows from a cannon in the hope of understanding the reason:
Imagine that 1000 people are accessing your host, and these 1000 people are in addition to downloading your site, they also make a request in the background before Yandex weather, Yandex will block you with so many requests per minute / second / other unit of measurement :)
In general, pull any data from external sites without caching and pre-processing - evil.
Just imagine how long your page will take to load if an external site suddenly becomes unavailable.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question