timocars En vacances.... | Bonjour,
Mon site utilise un lecteur de fichier xml. Il se trouve que parfois, quand les fichiers xml contiennent des erreurs, celui-ci se met à boucler et mon hébergeur n'aime pas ça du tout.....
Connaitriez-vous une fonction qui pourrait controler par exemple le temps depuis lequel le script tourne et l'arrêter le cas échéant...
Merci
Code :
- //Déclaration de la classe XML
- $date=date("d/m" );
- class xml {
- var $parser;
- function parse($xmlstring){
- $this->parser = xml_parser_create();
- xml_set_object($this->parser, $this);
- xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
- xml_set_element_handler($this->parser, "tag_open", "tag_close" );
- xml_set_character_data_handler($this->parser, "cdata" );
- // Initialisation
- $this->node_stack = array();
- $this->tag_open(null, "root", array());
- xml_parse($this->parser, $xmlstring);
- xml_parser_free($this->parser);
- $rnode = array_pop($this->node_stack);
- return($rnode);}
- function tag_open($parser, $tag, $attributes){
- // creation d'un nouveau node...
- $node = array();
- $node["_NAME"] = $tag;
- foreach ($attributes as $key => $value) {
- $node[$key] = $value;}
- $node["_DATA"] = "";
- $node["_ELEMENTS"] = array();
- // ajouter le nouveau node à la fin de la pile de node
- array_push($this->node_stack, $node); }
- function cdata($parser, $cdata){
- // ajouter les données au dernier node de la pile
- $lastnode = count($this->node_stack);
- $this->node_stack[$lastnode-1]["_DATA"] .= $cdata;}
- function tag_close($parser, $tag){
- // suppression de la pile
- $node = array_pop($this->node_stack);
- $node["_DATA"] = trim($node["_DATA"]);
- // and ajout comme élément à la fin de la pile...
- $lastnode = count($this->node_stack);
- array_push($this->node_stack[$lastnode-1]["_ELEMENTS"], $node);}
- }
- // récupération du fichier par paquets de 4096
- $fp = fopen($rssurl, "r" );
- while (!feof ($fp)) $data .= fgets($fp, 4096);
- fclose ($fp);
- $initPos = strpos($data, "<channel>" ); // Saut de l'entête
- //parse les données
- $xml_parser = new xml();
- $data = substr($data, $initPos);
- $root_node = $xml_parser->parse($data);
- $channel = array_shift($root_node["_ELEMENTS"]);
- $comp=0;
- //Lecture des données du RSS
- foreach ($channel["_ELEMENTS"] as $item){
- if($item[_NAME]=="item" and $comp<16) {
- unset($news_pubDate);
- unset($news_pub);
- unset($mod);
- // suppression des antislashs
- foreach ($item["_ELEMENTS"] as $tag){
- if($tag["_NAME"]=="title" ) $news_title=stripslashes($tag[_DATA]);
- if($tag["_NAME"]=="link" ) $news_url=stripslashes($tag[_DATA]);
- if($tag["_NAME"]=="dc:date" ) $news_pubDate=stripslashes($tag[_DATA]);
- if($tag["_NAME"]=="pubDate" ) $news_pub=stripslashes($tag[_DATA]);
- }
-
- if($news_pubDate!="" )
- {$tabl = explode("T",$news_pubDate);
- $tab = explode("-",$tabl[0]);
- $dat="$tab[2]/$tab[1]";}
- else
- {$mod=strtotime($news_pub);
- $dat=date("d/m",$mod);}
- if($dat==$date)
- {$news.="\n<b>$dat</b>-<a href=\"$news_url\" target=\"_new\">$news_title</a><br>"; }
- else
- {$news.="\n$dat-<a href=\"$news_url\" target=\"_new\">$news_title</a><br>";}
- $comp++;}
- }
- print"$news";
|
Message édité par timocars le 14-12-2004 à 18:33:55 ---------------
Webmaster de http://www.touthardware.com : annuaire de tests de hardware
|