Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
benchmark.php
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
017 $phpbb_root_path = "../";
018 include($phpbb_root_path . 'extension.inc');
019 include($phpbb_root_path . 'common.'.$phpEx);
020 include($phpbb_root_path . 'includes/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
055 // The script expects the ID's in the tables to sequential (1,2,3,4,5),
056 // so no holes please (1,4,5,8)...
057 $nr_of_users = nrof(USERS_TABLE);
058 $nr_of_cats = nrof(CATEGORIES_TABLE);
059 $nr_of_forums = nrof(FORUMS_TABLE);
060 $nr_of_posts = nrof(POSTS_TABLE);
061
062 $u = $users;
063
064 $starttime = microtime();
065
066 $usercreationcount = 0;
067 while($users > 0)
068 {
069
070 $name = "testuser_" . substr(md5(uniqid(rand())), 0, 10);
071 if (make_user($name))
072 {
073 $usercreationcount++;
074 $users--;
075 }
076 if (($usercreationcount % 500) == 0)
077 {
078 echo "status: $usercreationcount <br>\n";
079 flush();
080 }
081
082 }
083
084 if ($posts > 0)
085 {
086 filldb($posts);
087 }
088
089 $endtime = microtime();
090
091 if ($submit="" || !isset($submit))
092 {
093 ?>
094 Hello, welcome to this little phpBB Benchmarking script :)<p>
095
096 At the moment there are:<br>
097
098 <table>
099 <tr><td align="right"><?php echo $nr_of_users?></td><td>Users</td></tr>
100 <tr><td align="right"><?php echo $nr_of_forums?></td><td>Forums</td></tr>
101 <tr><td align="right"><?php echo $nr_of_posts?></td><td>Posts</td></tr>
102 </table>
103 <p>
104 What do you want to create?<p>
105
106 <form method="get" action="<?php echo $PHP_SELF?>">
107 <input type="text" name="users" size="3"> Users<br>
108 <input type="text" name="posts" size="3"> Posts/topics (optional: post size in <input type="text" name="size" size="3"> bytes)<br>
109 <input type="submit" name="submit">
110 </form>
111
112 <?php
113 }
114 else
115 {
116
117 list ($starttime_msec,$starttime_sec) = explode(" ",$starttime);
118 list ($endtime_msec,$endtime_sec) = explode(" ",$endtime);
119 $timetaken_sec = ($endtime_sec+$endtime_msec) - ($starttime_sec+$starttime_msec);
120 print "<B>TIME TAKEN : ".$timetaken_sec."s</B><BR>\n";
121
122 print "<p>\n<a href=\"$PHP_SELF\">Back to the overview page</a>\n";
123 }
124
125
126 function filldb($newposts)
127 {
128 global $nr_of_forums;
129 global $nr_of_users;
130
131 $forum_topic_counts = array();
132
133 for ($i = 1; $i <= $nr_of_forums; $i++)
134 {
135 $forum_topic_counts[$i] = get_topic_count($i);
136 }
137
138 for($i = 0; $i < $newposts; $i++)
139 {
140 $userid = rand(2, $nr_of_users - 1);
141 $forum = rand(1,$nr_of_forums);
142
143 if ((rand(0,30) < 1) || ($forum_topic_count[$forum] == 0))
144 {
145 // create a new topic 1 in 30 times (or when there are none);
146 $topic = make_topic($userid, "Testing topic $i", $forum);
147 $forum_topic_count[$forum]++;
148 }
149 else
150 {
151 // Otherwise create a reply(posting) somewhere.
152 $topic = get_smallest_topic($forum);
153 create_posting($userid, $topic, $forum, "reply");
154 }
155
156 if (($i % 1000) == 0)
157 {
158 echo "status: $i <br>";
159 flush();
160 }
161
162 }
163 }
164
165
166 function get_smallest_topic($forum_id)
167 {
168 global $db;
169
170 $sql = "SELECT topic_id
171 FROM " . TOPICS_TABLE . "
172 WHERE (forum_id = $forum_id)
173 ORDER BY topic_replies ASC LIMIT 1";
174 if($result = $db->sql_query($sql))
175 {
176 $row = $db->sql_fetchrow($result);
177 $topic_id = $row['topic_id'];
178
179 unset($result);
180 unset($row);
181 return $topic_id;
182 }
183 else
184 {
185 message_die(GENERAL_ERROR, "Couldn't get smallest topic.", "", __LINE__, __FILE__, $sql);
186 }
187
188 }
189
190
191 function get_topic_count($forum_id)
192 {
193 global $db;
194
195 $sql = "SELECT forum_topics
196 FROM " . FORUMS_TABLE . "
197 WHERE (forum_id = $forum_id)";
198 if($result = $db->sql_query($sql))
199 {
200 $row = $db->sql_fetchrow($result);
201 $topic_count = $row['forum_topics'];
202
203 unset($result);
204 unset($row);
205 return $topic_count;
206 }
207 else
208 {
209 message_die(GENERAL_ERROR, "Couldn't get topic count.", "", __LINE__, __FILE__, $sql);
210 }
211
212 }
213
214
215 function make_topic($user_id, $subject, $forum_id)
216 {
217 global $db;
218 $topic_type = POST_NORMAL;
219 $topic_vote = 0;
220 $current_time = time();
221
222 $sql = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote)
223 VALUES ('$subject', $user_id, $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)";
224
225 if( $result = $db->sql_query($sql, BEGIN_TRANSACTION) )
226 {
227 $new_topic_id = $db->sql_nextid();
228 }
229 else
230 {
231 message_die(GENERAL_ERROR, "Error inserting data into topics table", "", __LINE__, __FILE__, $sql);
232 }
233
234 create_posting($user_id, $new_topic_id, $forum_id);
235
236 return $new_topic_id;
237 }
238
239
240
241 function create_posting($userid, $topic_id, $forum, $mode='newtopic')
242 {
243 $message = generatepost();
244
245 return make_post($topic_id, $forum, $userid, "", $message, $mode);
246
247 }
248
249
250
251 function make_post($new_topic_id, $forum_id, $user_id, $post_username, $text, $mode='newtopic')
252 {
253 global $db;
254 $current_time = time();
255 $user_ip = "ac100202";
256 $bbcode_on = 1;
257 $html_on = 1;
258 $smilies_on = 1;
259 $attach_sig = 1;
260 $bbcode_uid = make_bbcode_uid();
261
262 $post_subject = 'random subject';
263
264 $post_message = prepare_message($text, $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
265
266 $sql = "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, attach_id, icon_id, post_username, post_time, poster_ip, post_approved, bbcode_uid, enable_bbcode, enable_html, enable_smilies, enable_sig, post_subject, post_text)
267 VALUES ($new_topic_id, $forum_id, $user_id, 0, 0, '$post_username', $current_time, '$user_ip', 1, '$bbcode_uid', $bbcode_on, $html_on, $smilies_on, $attach_sig, '$post_subject', '$post_message')";
268 $result = $db->sql_query($sql);
269
270 if ($result)
271 {
272 $new_post_id = $db->sql_nextid();
273
274 $sql = "UPDATE " . TOPICS_TABLE . "
275 SET topic_last_post_id = $new_post_id";
276 if($mode == "reply")
277 {
278 $sql .= ", topic_replies = topic_replies + 1 ";
279 }
280 $sql .= " WHERE topic_id = $new_topic_id";
281
282 if($db->sql_query($sql))
283 {
284 $sql = "UPDATE " . FORUMS_TABLE . "
285 SET forum_last_post_id = $new_post_id, forum_posts = forum_posts + 1";
286 if($mode == "newtopic")
287 {
288 $sql .= ", forum_topics = forum_topics + 1";
289 }
290 $sql .= " WHERE forum_id = $forum_id";
291
292 if($db->sql_query($sql))
293 {
294 $sql = "UPDATE " . USERS_TABLE . "
295 SET user_posts = user_posts + 1
296 WHERE user_id = " . $user_id;
297
298 if($db->sql_query($sql, END_TRANSACTION))
299 {
300 // SUCCESS.
301 return true;
302 }
303 else
304 {
305 message_die(GENERAL_ERROR, "Error updating users table", "", __LINE__, __FILE__, $sql);
306 }
307 }
308 else
309 {
310 message_die(GENERAL_ERROR, "Error updating forums table", "", __LINE__, __FILE__, $sql);
311 }
312 }
313 else
314 {
315 // Rollback
316 if($db->sql_layer == "mysql")
317 {
318 $sql = "DELETE FROM " . POSTS_TABLE . "
319 WHERE post_id = $new_post_id";
320 $db->sql_query($sql);
321 }
322 message_die(GENERAL_ERROR, "Error updating topics table", "", __LINE__, __FILE__, $sql);
323 }
324 }
325 else
326 {
327 message_die(GENERAL_ERROR, "Error inserting data into posts table", "", __LINE__, __FILE__, $sql);
328 }
329 }
330
331
332 function generatepost($size=850)
333 {
334 global $bigass_text;
335 // Returns a string with a length between $size and $size*0.2
336 $size = rand(0.2*$size, $size);
337
338 $textsize = strlen($bigass_text);
339 $currentsize = 0;
340 // Add whole $text multiple times
341 while($currentsize < $size && $size-$currentsize <= $textsize)
342 {
343 $message .= $bigass_text;
344 $currentsize += $textsize;
345 }
346 // Add the remainder number of chars and return it.
347 $message .= substr($bigass_text, 0, $size-$currentsize);
348
349 return (addslashes($message));
350 }
351
352
353 function nrof($table)
354 {
355 global $db;
356 $sql = "SELECT count(*) AS counted FROM $table";
357 $result = $db->sql_query($sql);
358 $topics = $db->sql_fetchrow($result);
359 return $topics[counted];
360 }
361
362
363 function make_user($username)
364 {
365 global $db, $board_config;
366
367 $password = md5("benchpass");
368 $email = "nobody@localhost";
369 $icq = "12345678";
370 $website = "http://www.phpbb.com";
371 $occupation = "phpBB tester";
372 $location = "phpBB world hq";
373 $interests = "Eating, sleeping, living, and breathing phpBB";
374 $signature = "$username: phpBB tester.";
375 $signature_bbcode_uid = "";
376 $avatar_filename = "";
377 $viewemail = 0;
378 $aim = 0;
379 $yim = 0;
380 $msn = 0;
381 $attachsig = 1;
382 $allowsmilies = 1;
383 $allowhtml = 1;
384 $allowbbcode = 1;
385 $allowviewonline = 1;
386 $notifyreply = 0;
387 $notifypm = 0;
388 $user_timezone = $board_config['board_timezone'];
389 $user_dateformat = $board_config['default_dateformat'];
390 $user_lang = $board_config['default_lang'];
391 $user_style = $board_config['default_style'];
392
393
394 $sql = "SELECT MAX(user_id) AS total
395 FROM " . USERS_TABLE;
396 if($result = $db->sql_query($sql))
397 {
398 $row = $db->sql_fetchrow($result);
399 $new_user_id = $row['total'] + 1;
400
401 unset($result);
402 unset($row);
403 }
404 else
405 {
406 message_die(GENERAL_ERROR, "Couldn't obtained next user_id information.", "", __LINE__, __FILE__, $sql);
407 }
408
409 $sql = "SELECT MAX(group_id) AS total
410 FROM " . GROUPS_TABLE;
411 if($result = $db->sql_query($sql))
412 {
413 $row = $db->sql_fetchrow($result);
414 $new_group_id = $row['total'] + 1;
415
416 unset($result);
417 unset($row);
418 }
419 else
420 {
421 message_die(GENERAL_ERROR, "Couldn't obtained next user_id information.", "", __LINE__, __FILE__, $sql);
422 }
423
424
425 $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_allowsmilies, 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)
426 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, ";
427
428
429 $sql .= "1, '')";
430
431 if($result = $db->sql_query($sql, BEGIN_TRANSACTION))
432 {
433 $sql = "INSERT INTO " . GROUPS_TABLE . " (group_id, group_name, group_description, group_single_user, group_moderator)
434 VALUES ($new_group_id, '', 'Personal User', 1, 0)";
435 if($result = $db->sql_query($sql))
436 {
437 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending)
438 VALUES ($new_user_id, $new_group_id, 0)";
439 if($result = $db->sql_query($sql, END_TRANSACTION))
440 {
441
442 // SUCCESS.
443 return true;
444 }
445 else
446 {
447 message_die(GENERAL_ERROR, "Couldn't insert data into user_group table", "", __LINE__, __FILE__, $sql);
448 }
449 }
450 else
451 {
452 message_die(GENERAL_ERROR, "Couldn't insert data into groups table", "", __LINE__, __FILE__, $sql);
453 }
454 }
455 else
456 {
457 message_die(GENERAL_ERROR, "Couldn't insert data into users table", "", __LINE__, __FILE__, $sql);
458 }
459
460 }
461
462 ?>