Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Pobieranie danych z RSS - optymalizacja
in5ane
post
Post #1





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Elo, pomógłby mi ktoś zoptymalizować poniższy kod? Chodzi o to, że on pobiera dane z RSS i je wyświetla, tylko problem w tym, że tak obciążał serwer, że usługodawca kazał mi się wynieść z serwera.

Kod:
  1. <?php
  2. $site = "http://www.ttrworldtour.com/ranking/mens-ranking-list.html?type=116&tx_txresults_pi1%5BfeedId%5D=53";
  3. $fp = @fopen($site,"r");
  4. while(!feof($fp)) $raw .= @fgets($fp, 196);
  5. fclose($fp);
  6.    echo '<p style="margin: 0 15px 0 15px;"><a href="http://www.ttrworldtour.com/ranking/mens-ranking-list.html" target="_top"><strong>TTR TOP 5 MEN</strong></a></p>';
  7. if( eregi("<item>(.*)</item>", $raw, $rawitems ) ) {
  8. $items = explode("<item>", $rawitems[0]);
  9.    
  10. for( $i = 0; $i < count($items)-1; $i++ ) {
  11.  eregi("<title>(.*)</title>",$items[$i+1], $title );
  12.  eregi("<link>(.*)</link>",$items[$i+1], $link );
  13.  eregi("<categorie>(.*)</categorie>",$items[$i+1], $cat);
  14.  echo "<p style=\"margin: 0 15px 0 15px;\"><a href='".$link[1]."' target='_top'>".$title[1]."</a> </p>".$cat[1];
  15. }
  16. }
  17.  
  18. echo '<br /><br />';
  19.  
  20. $sites = "http://www.ttrworldtour.com/ranking/womens-ranking-list.html?type=117&tx_txresults_pi1%5BfeedId%5D=53";
  21. $fps = @fopen($sites,"r");
  22. while(!feof($fps)) $raws .= @fgets($fps, 196);
  23. fclose($fps);
  24.    echo '<p style="margin: 0 15px 0 15px;"><a href="http://www.ttrworldtour.com/ranking/womens-ranking-list.html" target="_top"><strong>TTR TOP 5 WOMEN</strong></a></p>';
  25. if( eregi("<item>(.*)</item>", $raws, $rawitemss ) ) {
  26. $itemss = explode("<item>", $rawitemss[0]);
  27.  
  28. for( $i = 0; $i < count($itemss)-1; $i++ ) {
  29.  eregi("<title>(.*)</title>",$itemss[$i+1], $titles );
  30.  eregi("<link>(.*)</link>",$itemss[$i+1], $links );
  31.  eregi("<categorie>(.*)</categorie>",$itemss[$i+1], $cats);
  32.  echo "<p style=\"margin: 0 15px 0 15px;\"><a href='".$links[1]."' target='_top'>".$titles[1]."</a> </p>".$cats[1];
  33. }
  34. }
  35. ?>


Z góry dziękuję za pomoc.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
-gox-
post
Post #2





Goście







  1. <?php
  2. $site = "http://www.ttrworldtour.com/ranking/mens-ranking-list.html?type=116&tx_txresults_pi1%5BfeedId%5D=53";
  3. $data = @file_get_contents($site) or die('blad polaczenia');
  4. ?>
  5. <p style="margin: 0 15px 0 15px;"><a href="http://www.ttrworldtour.com/ranking/mens-ranking-list.html" target="_top"><strong>TTR TOP 5 MEN</strong></a></p>
  6. <?php
  7.    preg_match_all('#<item>(.*?)</item>#', $data, $items);
  8.    $items = $items[0];
  9.    $output = array();
  10.    $count = count($items);
  11.    <?php for($i=0; $i<$items; $i++): ?>
  12.    <?php
  13.        preg_match('#<title>(.*?)</title>#', $items[$i], $title);
  14.        $output[$i]['title'] = $title[1];
  15.        
  16.        preg_match('#<link>(.*?)</link>#', $items[$i], $link);
  17.        $output[$i]['link'] = $link[1];
  18.        
  19.        preg_match('#<categorie>(.*?)</<categorie>#', $items[$i], $categorie);
  20.        $output[$i]['categorie'] = $categorie[1];
  21.    ?>
  22.    <p style="margin: 0 15px 0 15px;"><a href="<?php echo $link[1];?>" target='_top'><?php echo $title[1];?></a></p><?php echo $categorie[1];?>
  23.    <?php endfor;?>
  24.        
  25.        <?
  26.            // teraz robisz sobie file_put_contents('db.txt', serialize($output));
  27.            // i zamiast laczyc sie co z zew. serwerem co chwila, robisz to np. raz na 5 minut
  28.            // a przez reszte czasu czytasz dane z pliku 'db.txt'
  29.            
  30.        ?>
  31.        
  32.        <?
  33.            
  34.            // drugiej czesci skryptu nie podaje bo jest praktycznie identyczna
  35.        
  36.        ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 21:09