Quantcast
Channel: PHP XML disable feed if offline - Stack Overflow
Viewing all articles
Browse latest Browse all 2

PHP XML disable feed if offline

$
0
0
<?php     define(feed,'http://www.example.com/feed/');     $xml_feed = file_get_contents(feed);     $xml_parser = xml_parser_create();     xml_parse_into_struct($xml_parser,$xml_feed,$xml_keys,$xml_index);     xml_parser_free($xml_parser);     for($i = 0;!empty($xml_index['TITLE'][$i]);$i++){     if ($counter < 10)     {     echo '<span class="nieuwsfeed"><a href="'.$xml_keys[$xml_index['LINK'][$i]]['value'].'" target="blank_">' . date('d-m-Y', strtotime($xml_keys[$xml_index['PUBDATE'][$i]]['value'])) . '' . substr($xml_keys[$xml_index['TITLE'][$i]]['value'], 0, 45).'</a></span>';     $counter++;     }}     ?>

.

 $doc = new DOMDocument(); $doc->load('http://feeds.example.com/example'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) {  $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue  );array_push($arrFeeds, $itemRSS); } foreach ($arrFeeds as $row){     if ($counter2 < 10){?>

This error is showing when the feed is offline.

      Warning: DOMDocument::load(http://feeds.example.com/example)         [domdocument.load]: failed to open stream: Connection timed out in

Im using this script to let my feeds run in my webpage, but IF the feed is offline, its searching for the feed for about 30 seconds till 60 seconds, does anyone has an idea how I should disable loading after an x amount of seconds and then showing just an standard image where it says the feed is currently offline.

Its about 2/3 times per week one of the XML feeds are offline, so it's pretty annoying if your webpage keeps loading.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images