Why, if the source for parsing is not working, the website is also not working?

Parsim the exchange rate of the national Bank, the national Bank was not working and it stops working a site that parses.
If for example to specify the source incorrectly, the site shows zero. Why if the source was available, not shown on the website of the zeros?

<?php 

 $sContent = file_get_contents("http://www.nationalbank.kz/rss/rates_all.xml", "r");
 $oXml = simplexml_load_string($sContent);
 $iUSD = 0;
 $iRUR = 0;
 $iEUR = 0;
 foreach($oXml--->channel->item AS $oValue) { 
 if ($oValue->title == "USD") { 
 $iUSD = $oValue->description; 
 } 
 if ($oValue->title == "RUB") { 
 $iRUB = $oValue->description; 
 } 
 if ($oValue->title == "EUR") { 
 $iEUR = $oValue->description; 
 } 
 } 

 echo "<span>USD " . $iUSD . "</span>";
 echo "<span>RUB " . $iRUB . "</span>";
 echo "<span>EUR " . $iEUR . "</span>";
?>
July 8th 19 at 11:19
4 answers
July 8th 19 at 11:21
Read the logs, everything is written.
July 8th 19 at 11:23
because it is one thread and there is a code - always asynchronous.
1. parasite and cache.
2. handle errors
3. use cache error
July 8th 19 at 11:25
Because default_socket_timeout in PHP is equal to 60 (seconds), and the maximum runtime file_get_contents depends on this parameter. Accordingly, if the website from which you pulled information is, then your website returns the response only after the expiry of this timeout.

Any PHP code that interacts with a network, it is desirable to make the tasks performed through cli via cron (although this is not always possible, for example when authorizing through a third party service), and the site display of cached results. It should do the validation that this code will not run 100500 times.

Plus, you have no checks file_get_contents and simplexml_load_string return a correct result.
July 8th 19 at 11:27
The script probably fails when data are not available.
Put $sContent = @file_get_contents or if wrap
$sContent = @file_get_contents costs - Peter.Oberbrunner84 commented on July 8th 19 at 11:30
But you can still squint. Also a good method of solving problems. - Amie commented on July 8th 19 at 11:33
? ) - Peter.Oberbrunner84 commented on July 8th 19 at 11:36
: Eyes closed you will not see the problem let alone fix it, and if you ignore the error. So these methods are almost equivalent. Really have to squint better, because the error will be able to see someone else, and ignoring likely not only not do better, but will make it worse. - Amie commented on July 8th 19 at 11:39
: do not email me the correct parser for the weather and course? - Peter.Oberbrunner84 commented on July 8th 19 at 11:42
No. Prompt I can, and to write boring. - Amie commented on July 8th 19 at 11:45

Find more questions by tags XMLParsingPHP