00001 <?php
00002
00006 define( "NUM_REQUESTS", 25 );
00007
00011 define( "BASE_URL", "http://localhost/trunk/" );
00012
00016 define( "GET_RATE", 70 );
00017
00021 define( "POST_RATE", 30 );
00022
00023 if (!defined( "PLOG_CLASS_PATH" )) {
00024 define( "PLOG_CLASS_PATH", dirname(__FILE__)."/../");
00025 }
00026
00027 include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
00028
00029
00030 $db =& Db::getDb();
00031
00032
00033 $postsResult = $db->Execute( "SELECT id, blog_id FROM ".Db::getPrefix()."articles WHERE status = 1 LIMIT 1,200" );
00034 while( $row = $postsResult->FetchRow()) {
00035 if( !isset( $postIds[$row["blog_id"]] ))
00036 $postIds[$row["blog_id"]] = Array();
00037
00038 $postIds[$row["blog_id"]][] = $row["id"];
00039 }
00040
00041
00042 $numBlogs = count( $postIds );
00043 $numReqs = 0;
00044
00045 while( $numReqs < NUM_REQUESTS ) {
00046
00047 $blogId = rand( 1, $numBlogs );
00048
00049
00050 $articleId = $postIds[$blogId][rand(0,count($postIds[$blogId])-1)];
00051
00052
00053 $reqType = rand(1,100);
00054 if( $reqType <= GET_RATE ) {
00055 $getType = rand(1,2);
00056 if( $getType == 1 ) {
00057
00058 $url = BASE_URL."index.php?op=Default&blogId=".$blogId;
00059 }
00060 else {
00061
00062 $url = BASE_URL."index.php?op=ViewArticle&blogId=".$blogId."&articleId=".$articleId;
00063 }
00064
00065 printGET( $url );
00066 }
00067 else {
00068
00069 $url = BASE_URL."index.php";
00070
00071 $form = Array ( "articleId" => $articleId, "op" => "AddComment", "commentTopic" => generateRandomWords(rand(1,15)),
00072 "commentText" => generateRandomParagraphs(rand(1,2)), "blogId" => $blogId,
00073 "userName" => "loadtest" );
00074
00075 printPOST( $url, $form );
00076 }
00077
00078 $numReqs++;
00079 }
00080
00084 Function printGET( $url )
00085 {
00086 print( "GET, $url\n" );
00087 }
00088
00092 function printPOST( $url, $formVars )
00093 {
00094 $string = "POST, $url, \"";
00095 $form = Array();
00096 foreach( $formVars as $key=>$value ) {
00097 $form[] = "$key=$value";
00098 }
00099 $formString = implode( "|", $form );
00100 $string .= "$formString\"\n";
00101 print($string);
00102 }
00103
00104 function generateRandomWord($lenght, $uppercase = false) {
00105 $newcode_length = 1;
00106 $newcode = "";
00107 while($newcode_length < $lenght) {
00108 $a=97;
00109 $b=122;
00110 if ($newcode_length == 1) {
00111 if (rand(1,4) == 1 || $uppercase) {
00112 $a=65;
00113 $b=90;
00114 }
00115 }
00116 $code_part=chr(rand($a,$b));
00117 $newcode_length++;
00118 $newcode = $newcode.$code_part;
00119 }
00120 return $newcode;
00121 }
00122
00123 function generateRandomWords( $count, $uppercase = false, $html = true) {
00124 $words = generateRandomWord( rand( 3, 12), $uppercase );
00125 for ($i = 1; $i < $count; $i++) {
00126 $rand = rand(3, 12);
00127 $words .= ' ' . generateRandomWord( $rand );
00128 }
00129 return $words;
00130 }
00131
00132 function generateRandomParagraph() {
00133 $length = rand( 3, 20 );
00134 $counter = 0;
00135 $text = '<p>' . generateRandomWord( rand( 3, 12 ), true );
00136 while ($counter < $length) {
00137 $word = generateRandomWords( rand(3, 12) );
00138 $text = $text . ' ' . $word;
00139 $counter++;
00140 }
00141 $text .= "</p>";
00142 return $text;
00143 }
00144
00145 function generateRandomParagraphs( $count ) {
00146 $text = '';
00147 for ($i = 1; $i < $count; $i++) {
00148 $text .= generateRandomParagraph();
00149 }
00150 return $text;
00151 }
00152 ?>