Verzeichnisstruktur phpBB-2.0.0


Veröffentlicht
03.04.2002

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

benchmark.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 11.26 KiB


001  <?php
002   
003  //
004  // Security message:
005  //
006  // This script is potentially dangerous.
007  // Remove or comment the next line (die(".... ) to enable this script.
008  // Do NOT FORGET to either remove this script or disable it after you have used it.
009  //
010  die("Please read the first lines of this script for instructions on how to enable it");
011   
012  //
013  // Do not change anything below this line.
014  //
015   
016  define('IN_PHPBB', true);
017  $phpbb_root_path = "../";
018  include($phpbb_root_path . 'extension.inc');
019  include($phpbb_root_path . 'common.'.$phpEx);
020  include($phpbb_root_path . 'includes/functions_post.'.$phpEx);
021  include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
022   
023  srand ((double) microtime() * 1000000);
024  set_time_limit(240*60);
025   
026  // Here's the text we stick in posts..
027  $bigass_text = 
028  phpBB BBCode test suite v0.0.2
029  auto-linkification:
030  http://something.com
031  www.something.com
032  nate@phpbb.com
033  http://something.com/foo.php?this=that&theother=some%20encoded%20string is a link.
034  [code]
035  Simple code block with some <html> <tags>.
036  [/code]
037  [b]bolded[/b], [i]italic[/i]
038  [email]james@totalgeek.org[/email]
039  [url=http://www.totalgeek.org]totalgeek.org[/url]
040  [url]www.totalgeek.org[/url] 
041  [list] 
042  [*] This is the first bulleted item.
043  [*] This is the second bulleted item.
044  [/list] 
045  [list=A] 
046  [*] This is the first bulleted item.
047  [*] This is the second bulleted item.
048  [/list] 
049  [quote]
050  And a quote!
051  [/quote]
052  ';
053   
054  $users = intval($HTTP_GET_VARS['users']);
055  $posts = intval($HTTP_GET_VARS['posts']);
056  $size = intval($HTTP_GET_VARS['size']);
057   
058  // The script expects the ID's in the tables to sequential (1,2,3,4,5), 
059  // so no holes please (1,4,5,8)...
060  $nr_of_users  = nrof(USERS_TABLE);
061  $nr_of_cats   = nrof(CATEGORIES_TABLE);
062  $nr_of_forums = nrof(FORUMS_TABLE);
063  $nr_of_posts  = nrof(POSTS_TABLE);
064   
065  $u = $users;
066   
067  $starttime = microtime();
068   
069  $usercreationcount = 0;
070  while($users > 0)
071  {
072   
073      $name = "testuser_" . substr(md5(uniqid(rand())), 0, 10);
074      if (make_user($name))
075      {
076          $usercreationcount++;
077          $users--;
078      }
079      if (($usercreationcount % 500) == 0)
080      {
081          echo "status: $usercreationcount <br>\n";
082          flush();
083      }
084      
085  }
086   
087  if ($posts > 0)
088  {
089      filldb($posts);
090  }
091   
092  $endtime = microtime();
093   
094  $submit = (isset($HTTP_GET_VARS['submit'])) ? true : false;
095   
096  if (!$submit)
097  {
098      ?>
099  Hello, welcome to this little phpBB Benchmarking script :)<p>
100   
101  At the moment there are:<br>
102   
103  <table>
104  <tr><td align="right"><?php echo $nr_of_users?></td><td>Users</td></tr>
105  <tr><td align="right"><?php echo $nr_of_forums?></td><td>Forums</td></tr>
106  <tr><td align="right"><?php echo $nr_of_posts?></td><td>Posts</td></tr>
107  </table>
108  <p>
109  What do you want to create?<p>
110   
111  <form method="get" action="<?php echo $PHP_SELF?>">
112  <input type="text" name="users" size="3"> Users<br>
113  <input type="text" name="posts" size="3"> Posts/topics (optional: post size in <input type="text" name="size" size="3"> bytes)<br>
114  <input type="submit" name="submit">
115  </form>
116   
117      <?php
118  } 
119  else 
120  {
121   
122      list ($starttime_msec,$starttime_sec) = explode(" ",$starttime);
123      list ($endtime_msec,$endtime_sec) = explode(" ",$endtime);
124      $timetaken_sec = ($endtime_sec+$endtime_msec) - ($starttime_sec+$starttime_msec);
125      print "<B>TIME TAKEN : ".$timetaken_sec."s</B><BR>\n"; 
126   
127      print "<p>\n<a href=\"$PHP_SELF\">Back to the overview page</a>\n";
128  }
129   
130   
131  function filldb($newposts)
132  {
133      global $nr_of_forums;
134      global $nr_of_users;
135    
136      $forum_topic_counts = array();
137    
138      for ($i = 1; $i <= $nr_of_forums; $i++)
139      {
140            $forum_topic_counts[$i] = get_topic_count($i);
141      }
142    
143      for($i = 0; $i < $newposts; $i++)
144      {
145          $userid   = rand(2, $nr_of_users - 1);
146          $forum    = rand(1,$nr_of_forums);
147          
148          if ((rand(0,30) < 1) || ($forum_topic_count[$forum] == 0))
149          {
150              // create a new topic 1 in 30 times (or when there are none);
151              $topic = make_topic($userid, "Testing topic $i", $forum);
152              $forum_topic_count[$forum]++;
153          } 
154          else 
155          {
156              // Otherwise create a reply(posting) somewhere.
157              $topic = get_smallest_topic($forum);
158              create_posting($userid, $topic, $forum, "reply");
159          }
160          
161          if (($i % 1000) == 0)
162          {
163              echo "status: $i <br>";
164              flush();
165          }
166       
167      }
168  }
169   
170   
171  function get_smallest_topic($forum_id)
172  {
173      global $db;
174      
175      $sql = "SELECT topic_id
176          FROM " . TOPICS_TABLE . "
177          WHERE (forum_id = $forum_id)
178          ORDER BY topic_replies ASC LIMIT 1";
179      if($result = $db->sql_query($sql))
180      {
181          $row = $db->sql_fetchrow($result);
182          $topic_id = $row['topic_id'];
183   
184          unset($result);
185          unset($row);
186          return $topic_id;
187      }
188      else
189      {
190          message_die(GENERAL_ERROR, "Couldn't get smallest topic.", "", __LINE__, __FILE__, $sql);
191      }
192      
193  }
194   
195   
196  function get_topic_count($forum_id)
197  {
198      global $db;
199      
200      $sql = "SELECT forum_topics
201          FROM " . FORUMS_TABLE . "
202          WHERE (forum_id = $forum_id)";
203      if($result = $db->sql_query($sql))
204      {
205          $row = $db->sql_fetchrow($result);
206          $topic_count = $row['forum_topics'];
207   
208          unset($result);
209          unset($row);
210          return $topic_count;
211      }
212      else
213      {
214          message_die(GENERAL_ERROR, "Couldn't get topic count.", "", __LINE__, __FILE__, $sql);
215      }
216      
217  }
218   
219   
220  function make_topic($user_id, $subject, $forum_id)
221  {
222      global $db;
223      $topic_type = POST_NORMAL;
224      $topic_vote = 0;
225      $current_time = time();
226      
227      $sql = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) 
228          VALUES ('$subject', $user_id$current_time$forum_id" . TOPIC_UNLOCKED . "$topic_type$topic_vote)";
229   
230      if( $result = $db->sql_query($sql) )
231      {
232          $new_topic_id = $db->sql_nextid();
233      }
234      else
235      {
236          message_die(GENERAL_ERROR, "Error inserting data into topics table", "", __LINE__, __FILE__, $sql);
237      }
238      
239      create_posting($user_id, $new_topic_id, $forum_id);
240      
241      return $new_topic_id;
242  }
243   
244   
245   
246  function create_posting($userid, $topic_id, $forum, $mode = 'newtopic')
247  {
248      $message = generatepost();
249   
250      return make_post($topic_id, $forum, $userid, "", $message, $mode);
251  }
252   
253  function make_post($new_topic_id, $forum_id, $user_id, $post_username, $text, $mode = 'newtopic')
254  {
255      global $db;
256      $current_time = time();
257      $user_ip = "ac100202";
258      $bbcode_on = 1;
259      $html_on = 1;
260      $smilies_on = 1;
261      $attach_sig = 1;
262      $bbcode_uid = make_bbcode_uid();
263      
264      $post_subject = 'random subject';
265      
266      $post_message = prepare_message($text, $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
267      
268      $sql = "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig) 
269          VALUES ($new_topic_id$forum_id$user_id, '$post_username', $current_time, '$user_ip', $bbcode_on$html_on$smilies_on$attach_sig)";
270      $result = $db->sql_query($sql);
271      
272      if($result)
273      {
274          $new_post_id = $db->sql_nextid();
275      
276          $sql = "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) 
277              VALUES ($new_post_id, '$post_subject', '$bbcode_uid', '$post_message')";
278      
279          if($db->sql_query($sql))
280          {
281              $post_data = array();
282              $post_data['first_post'] = false;
283              $post_data['last_post'] = true;
284   
285              $sql = "SELECT SUM(post_id) as total FROM " . POSTS_TABLE . " WHERE topic_id = " . $new_topic_id;
286              $result = $db->sql_query($sql);
287              $row = $db->sql_fetchrow($result);
288              $total = intval($row['total']);
289   
290              if ($total == 1)
291              {
292                  $post_data['first_post'] = true;
293              }
294              
295              $sql = "SELECT forum_last_post_id
296                  FROM " . FORUMS_TABLE . "
297                  WHERE forum_id = $forum_id";
298              $result = $db->sql_query($sql);
299              $row = $db->sql_fetchrow($result);
300              $post_data['last_topic'] = ( $row['forum_last_post_id'] == $new_post_id ) ? true : false;
301   
302              update_post_stats($mode, $post_data, $forum_id, $new_topic_id, $new_post_id, $user_id);
303          }
304          else
305          {
306              // Rollback
307              if(SQL_LAYER == "mysql")
308              {
309                  $sql = "DELETE FROM " . POSTS_TABLE . "
310                      WHERE post_id = $new_post_id";
311                  $db->sql_query($sql);
312              }
313              message_die(GENERAL_ERROR, "Error inserting data into posts text table", "", __LINE__, __FILE__, $sql);
314          }
315      }
316      else
317      {
318          message_die(GENERAL_ERROR, "Error inserting data into posts table", "", __LINE__, __FILE__, $sql);
319      }    
320  }
321   
322   
323  function generatepost($size = 850)
324  {
325     global $bigass_text;
326     // Returns a string with a length between $size and $size*0.2
327     $size = rand(0.2*$size, $size);
328     
329     $textsize = strlen($bigass_text);
330     $currentsize = 0;
331     // Add whole $text multiple times
332     while($currentsize < $size && $size-$currentsize <= $textsize)
333     {
334        $message .= $bigass_text;
335        $currentsize += $textsize;
336     }
337     // Add the remainder number of chars and return it.
338     $message .= substr($bigass_text, 0, $size-$currentsize);
339   
340     return (addslashes($message));
341  }
342     
343        
344  function nrof($table)
345  {
346      global $db;
347      $sql = "SELECT count(*) AS counted FROM $table";
348      $result = $db->sql_query($sql);
349      $topics = $db->sql_fetchrow($result);
350      return $topics[counted];
351  }
352   
353   
354  function make_user($username)
355  {
356      global $db, $board_config;
357   
358      $password = md5("benchpass");
359      $email = "nobody@localhost";
360      $icq = "12345678";
361      $website = "http://www.phpbb.com";
362      $occupation = "phpBB tester";
363      $location = "phpBB world hq";
364      $interests = "Eating, sleeping, living, and breathing phpBB";
365      $signature = "$username: phpBB tester.";
366      $signature_bbcode_uid = "";
367      $avatar_filename = "";
368      $viewemail = 0;
369      $aim = 0;
370      $yim = 0;
371      $msn = 0;
372      $attachsig = 1;
373      $allowsmilies = 1;
374      $allowhtml = 1;
375      $allowbbcode = 1;
376      $allowviewonline = 1;
377      $notifyreply = 0;
378      $notifypm = 0;
379      $user_timezone = $board_config['board_timezone'];
380      $user_dateformat = $board_config['default_dateformat'];
381      $user_lang = $board_config['default_lang'];
382      $user_style = $board_config['default_style'];
383   
384   
385      $sql = "SELECT MAX(user_id) AS total
386          FROM " . USERS_TABLE;
387      if($result = $db->sql_query($sql))
388      {
389          $row = $db->sql_fetchrow($result);
390          $new_user_id = $row['total'] + 1;
391   
392          unset($result);
393          unset($row);
394      }
395      else
396      {
397          message_die(GENERAL_ERROR, "Couldn't obtained next user_id information.", "", __LINE__, __FILE__, $sql);
398      }
399   
400      $sql = "INSERT INTO " . USERS_TABLE . "    (user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey)
401          VALUES ($new_user_id, '$username', " . time() . ", '$password', '$email', '$icq', '$website', '$occupation', '$location', '$interests', '$signature', '$signature_bbcode_uid', '$avatar_filename', $viewemail, '$aim', '$yim', '$msn', $attachsig$allowsmilies$allowhtml$allowbbcode$allowviewonline$notifyreply$notifypm$user_timezone, '$user_dateformat', '$user_lang', $user_style, 0, 1, ";
402   
403      
404      $sql .= "1, '')";
405      
406      if($result = $db->sql_query($sql, BEGIN_TRANSACTION))
407      {
408          $sql = "INSERT INTO " . GROUPS_TABLE . " (group_name, group_description, group_single_user, group_moderator)
409              VALUES ('', 'Personal User', 1, 0)";
410          if($result = $db->sql_query($sql))
411          {
412              $group_id = $db->sql_nextid();
413              
414              $sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending)
415                  VALUES ($new_user_id$group_id, 0)";
416              if($result = $db->sql_query($sql, END_TRANSACTION))
417              {
418                  
419                  // SUCCESS.
420                  return true;
421              }
422              else
423              {
424                  message_die(GENERAL_ERROR, "Couldn't insert data into user_group table", "", __LINE__, __FILE__, $sql);
425              }
426          }
427          else
428          {
429              message_die(GENERAL_ERROR, "Couldn't insert data into groups table", "", __LINE__, __FILE__, $sql);
430          }
431      }
432      else
433      {
434          message_die(GENERAL_ERROR, "Couldn't insert data into users table", "", __LINE__, __FILE__, $sql);
435      }
436   
437  }
438   
439   
440   
441   
442    
443  ?>