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







Ostrzegam ze kodzik nie jest zdebugowany (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

  1. <?php
  2. $site = "http://www.ttrworldtour.com/ranking/mens-ranking-list.html?type=116&tx_txresults_pi1%5BfeedId%5D=53";
  3. $dbpath = './db/';
  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.    if ( ! is_dir($db_path))
  8.        @mkdir($dbpath, 0777) or die('nie moge utworzyc bazy danych, zrob to recznie (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) ');
  9.    
  10.    list($dbfile) = glob("{$dbpath}*");
  11.    
  12.    if ( is_file($dbfile) AND intval($dbfile) > ( time() - 60) ) {
  13.        $output = @unserialize(@file_get_contents($dbfile)) or die('nie moge odczytac pliq');
  14.    }
  15.    else {
  16.        preg_match_all('#<item>(.*?)</item>#', $data, $items);
  17.        $items = $items[0];
  18.        $output = array();
  19.        $count = count($items);
  20.        for($i=0; $i<$items; $i++) {
  21.            preg_match('#<title>(.*?)</title>#', $items[$i], $title);
  22.            $output[$i]['title'] = $title[1];
  23.            preg_match('#<link>(.*?)</link>#', $items[$i], $link);
  24.            $output[$i]['link'] = $link[1];
  25.            preg_match('#<categorie>(.*?)</<categorie>#', $items[$i], $categorie);
  26.            $output[$i]['categorie'] = $categorie[1];
  27.        }
  28.        @unlink($dbfile) or die('nie moge usunac pliq');
  29.        @file_put_contents($dbpath.time(), serialize($output)) or die('nie moge zapisac pliq');
  30.    }
  31.    
  32.    <?php foreach ( $output as $o )
  33.        <p style="margin: 0 15px 0 15px;"><a href="<?php echo $o['link'];?>" target='_top'><?php echo $o['title'];?></a></p><?php echo $o['categorie'];?>
  34.    <?php endforeach; ?>
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: 3.10.2025 - 02:35