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







cos kiepsciutensko zdebugowales w takim razie :0

  1. <?php
  2. $start=microtime();
  3. $site = "http://www.ttrworldtour.com/ranking/mens-ranking-list.html?type=116&tx_txresults_pi1%5BfeedId%5D=53";
  4. $dbpath = './db/';
  5. $storing_time = 10;
  6. ?>
  7. <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>
  8. <?php
  9.  if ( ! is_dir($dbpath))
  10.      @mkdir($dbpath, 0777) or die('nie moge utworzyc bazy danych, zrob to recznie tongue.gif');
  11.  
  12.  list($dbfile) = glob("{$dbpath}*");
  13.  
  14.  if ( is_file($dbfile) AND ( time() - preg_replace('#[^0-9]#', '', $dbfile) ) < $storing_time )  {
  15.        echo 'back';
  16.      $output = @unserialize(@file_get_contents($dbfile)) or die('nie moge odczytac pliq');
  17.  } else {
  18.        $data = @file_get_contents($site) or die('blad polaczenia');
  19.      preg_match_all('#<item>(.*?)</item>#s', $data, $items);
  20.      $items = $items[0];
  21.      $output = array();
  22.      $count = count($items);
  23.      if ( $count < 1) die('pusto');
  24.      for($i=0; $i<$count; $i++) {
  25.          preg_match('#<title>(.*?)</title>#s', $items[$i], $title);
  26.          $output[$i]['title'] = $title[1];
  27.          preg_match('#<link>(.*?)</link>#s', $items[$i], $link);
  28.          $output[$i]['link'] = $link[1];
  29.          preg_match('#<description>(.*?)</<description>#s', $items[$i], $description);
  30.          $output[$i]['description'] = $description[1];
  31.      }
  32.      @unlink($dbfile);// or die('nie moge usunac pliq');
  33.      @file_put_contents($dbpath.time(), serialize($output)) or die('nie moge zapisac pliq');
  34.  }
  35. ?>
  36.  
  37.  <?php foreach ($output as $o) { ?>
  38.      <p style="margin: 0 15px 0 15px;"><a href="<?php echo $o['link']; ?>" target='_top'><?php echo $o['title']; ?></a></p><?php echo $o['description']; ?>
  39.  <?php } ?>
  40.  <br /><br /><br /><br />
  41. <?php
  42. echo round(microtime()-$start, 6);
  43. ?>
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: 8.10.2025 - 05:24