Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> zbyt długie wykonywanie skryptu php
sylwekb
post
Post #1





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 12.01.2006

Ostrzeżenie: (0%)
-----


Dostawca hostingu zwrócił uwagę na zbyt długie wykonywanie poniższego kodu skryptu forum W-AGORA, w czym może być problem, czyżby jakieś polecenia php uległy modyfikacji i po aktualizacji wersji php są problemy, czy można to jakoś zmodyfikować?

  1. <?php
  2.  
  3. $bn_action="download";
  4. $bn_action_mode="R";
  5. require ("init.inc");
  6.  
  7. function displayNote ($key) {
  8. global $inc_dir, $ext, $site, $bn, $db, $auth, $bn_db, $bn_action, $bn_pad;
  9. global $bn_dir, $bn_dir_notes, $bn_dir_default, $icon_dir, $bn_before_access, $bn_doc_var;
  10. global $bn_user_mail, $bn_thread, $bn_modify, $bn_delete, $is_moderator;
  11. global $bn_win_width, $bn_win_height;
  12.  
  13. $has_children=is_array($db->children[$key]);
  14.  
  15. $bn_action="view";
  16.  
  17. // evaluate all variables
  18. if ($key>0) {
  19. extract ($db->entries[$key]);
  20. }
  21.  
  22. // we don't display key 0 (administrative note)
  23. // and don't display old notes (if list only new)
  24. if ( ($hidden && $auth->level<MODER) || ($key == 0) ) {
  25. $hidden_note = true;
  26. } else {
  27. // initialize links variables
  28. if ($bn_user_mail && $bn_thread) {
  29. $subscribe_thread_url = "subscribe_thread.$ext?site=$site&bn=$bn&thread=$thread";
  30. $subscribe_thread_text = LABEL_SUBSCRIBE_THREAD;
  31. $subscribe_thread_link = anchorWindow ($subscribe_thread_url, $subscribe_thread_text, ALT_RECEIVE_UPDATES, 620, 460);
  32. }
  33.  
  34. // CLOSE
  35. $close_url = "";
  36. if ($is_moderator && $bn_thread) {
  37. $close_url = "close.$ext?bn=$bn&key=$key";
  38. $close_text = LABEL_CLOSE_OPEN_THREAD;
  39. $close_link = anchor ($close_url, "", $close_text, $close_text );
  40. }
  41.  
  42. if (!empty($bn_before_access)) {
  43. if (file_exists ("$bn_dir/$bn_before_access") ) {
  44. include "$bn_dir/$bn_before_access";
  45. } else {
  46. include "$bn_dir_default/$bn_before_access";
  47. }
  48. } elseif (file_exists ("$bn_dir_default/before_access.$ext") ) {
  49. include ("$bn_dir_default/before_access.$ext");
  50. }
  51. printf ("\n<a name=\"N%s\"></a>\n", $key);
  52. $viewkey = $key;
  53. require ("$inc_dir/viewnote.$ext");
  54. }
  55.  
  56. if ( is_array($db->children[$key]) ) {
  57. // display all replies to this thread
  58. reset ($db->children[$key]);
  59. while ( $child=current($db->children[$key]) ) {
  60. $nextchild = next($db->children[$key]);
  61. if ($parent == 0) {
  62. printf ("\n<p><a name=\"T%s\"></a><div align=\"right\">", $child);
  63. printf ("<a href=\"#top\">%s</a>&nbsp;&nbsp;&nbsp;&nbsp;</div>\n", LABEL_TOP);
  64. if ($nextchild) {
  65. printf ("<div align=right><a href=\"#T${nextchild}\">%s</a>&nbsp;</div>", LABEL_NEXT_THREAD);
  66. }
  67. }
  68. // print "<blockquote>";
  69. displayNote ($child);
  70. // print "</blockquote>";
  71. }
  72. }
  73. }
  74.  
  75. /* Execute before_access program */
  76. if (!empty($bn_before_access)) {
  77. if (file_exists ("$bn_dir/$bn_before_access") ) {
  78. include "$bn_dir/$bn_before_access";
  79. } else {
  80. include "$bn_dir_default/$bn_before_access";
  81. }
  82. } elseif (file_exists ("$bn_dir_default/before_access.$ext") ) {
  83. include ("$bn_dir_default/before_access.$ext");
  84. }
  85.  
  86. display_header (TITLE_DOWNLOAD_FORUM, $header_footer);
  87. if (empty($bn)) {
  88. msgForm (ERROR_NO_FORUM_SPECIFIED, "$main_page", "", "_top");
  89. }
  90.  
  91. $unit = (isset($unit)) ? $unit : "7";
  92.  
  93. if ( 0 == (integer)$unit ) {
  94. $period = "";
  95. } else {
  96. $period = (empty($period)) ? "1" : $period;
  97. }
  98.  
  99. beginForm();
  100. print ("<a name=\"top\"></a>");
  101. print LABEL_SHOW_ACTIVE_THREADS;
  102. textField ("period", $period, 3);
  103. $units = array (
  104. "0" => LABEL_SHOW_ALL,
  105. "1" => LABEL_DAYS,
  106. "7" => LABEL_WEEKS,
  107. "30" => LABEL_MONTHS
  108. );
  109. listBox ("unit", $units, $unit);
  110. submitButton ("go", LABEL_GO);
  111. endForm();
  112.  
  113. # Gets listing outline
  114. # --------------------
  115. if (!empty($bn_list_vars) && file_exists ("$bn_dir/$bn_list_vars") ) {
  116. include "$bn_dir/$bn_list_vars";
  117. } elseif (file_exists ("$bn_dir_default/list.$ext") ) {
  118. include ("$bn_dir_default/list.$ext");
  119. }
  120.  
  121. if (empty($bn_digest_even_first_line) ) { // even first line should not be empty if defined
  122. $bn_digest_header = "<div align=left><ul>";
  123. $bn_digest_odd_first_line = "<li><font size=-1>\$formated_date</font> <a href='#N\$key'><em>\$subject</em></a> \$att_icon (\$username)";
  124. $bn_digest_even_first_line = "<li><font size=-1>\$formated_date</font> <a href='#N\$key'><em>\$subject</em></a> \$att_icon (\$username)";
  125. $bn_digest_begin_level = "<ul>";
  126. $bn_digest_odd_line = "<li><font size=-1>\$formated_date</font> <a href='#N\$key'><em>\$subject</em></a> \$att_icon (\$username)";
  127. $bn_digest_even_line = "<li><font size=-1>\$formated_date</font> <a href='#N\$key'><em>\$subject</em></a> \$att_icon (\$username)";
  128. $bn_digest_end_level = "</ul>";
  129. $bn_digest_footer = "</ul></div>";
  130. }
  131.  
  132. # gets all notes from the forum
  133. # -----------------------------
  134. $list_var["body"]=1;
  135. $expnd="all";
  136.  
  137. if ($period>0) {
  138. $last = $now - ($period * $unit * 24*60*60);
  139. } else {
  140. $last = 0;
  141. }
  142.  
  143. if ($totalnotes == 0) {
  144. msgWarning (sprintf(ERROR_NO_ENTRY_FOUND, $msg[0]));
  145. echo "</body></html>";
  146. }
  147.  
  148. $ret = $db->listThreads ($bn_db, 0, 0, "newest>$last", 1, 0);
  149.  
  150. # displays notes listing
  151. # -----------------------
  152. if (!is_array ($ret) || ($ret < 0)) {
  153. echo "<CENTER><strong>"; printf(ERROR_DATABASE, $ret); echo "</STRONG></CENTER>";
  154. } else {
  155. require_once "$inc_dir/listrenderer.$ext";
  156. $list =& new ListRenderer($db);
  157. $list->displayList(0, 'digest');
  158. }
  159.  
  160. # Now display each individual note
  161. # --------------------------------
  162. $bn_action="view";
  163.  
  164. # include Note template
  165. # ----------------------
  166. if (!empty($bn_template) && file_exists ("$bn_dir/$bn_template") ) {
  167. include "$bn_dir/$bn_template";
  168. } elseif (file_exists ("$bn_dir_default/template.$ext") ) {
  169. include ("$bn_dir_default/template.$ext");
  170. }
  171.  
  172. ## $bn_doc_var="<p><STRONG>\$formated_date <font color=\"#339900\">\$subject</font></strong><P>\$body<br><P><a href='mailto:\$useraddress?subject=[\$bn] \$subject'>\$username</a>";
  173.  
  174. if (is_array($db->entries)) {
  175. reset($db->entries);
  176. displayNote(0);
  177. }
  178.  
  179. # Display footer
  180. # --------------
  181. display_footer ($header_footer);
  182. ?>
  183.  
Go to the top of the page
+Quote Post
daniel1302
post
Post #2





Grupa: Zarejestrowani
Postów: 602
Pomógł: 30
Dołączył: 1.08.2007
Skąd: Nowy Sącz

Ostrzeżenie: (0%)
-----


My ci tutaj nie pomożemy, stosujesz nieznane dla nas klasy, funkcje itp. Kod wygląda ble... Bardzo razi w oczy global.....
Użyj funkcji
na początku i na końcu, potem odejmij od siebie czasy i usuwaj po kolei fragmenty kodu i zobatrz co tak długo trwa.
Czytnij:
http://php.webtutor.pl/pl/2011/04/12/jak-o...zez-skrypt-php/
Go to the top of the page
+Quote Post
sylwekb
post
Post #3





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 12.01.2006

Ostrzeżenie: (0%)
-----


Wielkie dzięki, dla jasności nie jestem autorem tego "ble" skryptu tylko W-AGORA, także nie mogę się w nim połapać dlatego zadałem pytanie, może ktoś z tym "wynalazkiem" się kiedyś spotkał i pomoże. Rzuciłem zapytanie na forum twórcy skryptu ale na razie bez odpowiedzi, w sumie nie piszą tam nic o wysyceniu procesora, a jak widzę były zakładane i funkcjonują we Francji, Anglii i USA.
Go to the top of the page
+Quote Post
Uriziel01
post
Post #4





Grupa: Zarejestrowani
Postów: 307
Pomógł: 37
Dołączył: 9.11.2010
Skąd: Zielona Góra

Ostrzeżenie: (0%)
-----


1)O Boże ta ilość Global'i, ten kto to pisał miał `nieciekawą` technikę tworzenia kodu.
2)Ogarniasz jakiekolwiek modyfikację tego kodu mając taka ilość kodu HTML we wnętrzu logiki ?
3)Widzimy tutaj zbyt mało, po tak małym kawałku kodu można jedynie powiedzieć że jest źle nieciekawie napisny, nic poza tym.
4)Zainteresuj sie narzędziami w stylu XDebug, posiada on tak zwany Profiler który potrafi ci ładnie (no ok, wiem że nie ładnie, ale sa skrypty które potrafią to ładnie opakować biggrin.gif) wypisać ile czasu trwały poszczególne etapy generowania strony w PHP (i nie tylko).
LINK:
http://xdebug.org/

Ten post edytował Uriziel01 8.12.2011, 07:44:58
Go to the top of the page
+Quote Post
by_ikar
post
Post #5





Grupa: Zarejestrowani
Postów: 1 798
Pomógł: 307
Dołączył: 13.05.2009
Skąd: Gubin/Wrocław

Ostrzeżenie: (0%)
-----


Cytat
1)O Boże ta ilość Global'i, ten kto to pisał miał `nieciekawą` technikę tworzenia kodu.

Moje pierwsze wrażenie było identyczne wink.gif

Tak jak kolega wyżej, również polecam ci nawet na localhost wrzucić stronę (wampserver ma wbudowany xdebug), odpalić xdebuga, podejrzeć wyniki w webgrind i zobaczyć na co idzie najwięcej czasu.

Cytat
2)Ogarniasz jakiekolwiek modyfikację tego kodu mając taka ilość kodu HTML we wnętrzu logiki ?

Są cms'y które mają jeszcze bardziej html pomieszany z php, niekiedy w taki sposób żeby do czegokolwiek dojść, trzeba znać cms na wylot tongue.gif
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 05:00