Execute( "SELECT id, blog_id FROM ".Db::getPrefix()."articles WHERE status = 1 LIMIT 1,200" ); while( $row = $postsResult->FetchRow()) { if( !isset( $postIds[$row["blog_id"]] )) $postIds[$row["blog_id"]] = Array(); $postIds[$row["blog_id"]][] = $row["id"]; } // generate some random links to blogs $numBlogs = count( $postIds ); $numReqs = 0; while( $numReqs < NUM_REQUESTS ) { // select a random blog $blogId = rand( 1, $numBlogs ); // and a random article from this blog $articleId = $postIds[$blogId][rand(0,count($postIds[$blogId])-1)]; // find out whether this is a POST or a GET request $reqType = rand(1,100); if( $reqType <= GET_RATE ) { $getType = rand(1,2); if( $getType == 1 ) { // generate a link to the blog $url = BASE_URL."index.php?op=Default&blogId=".$blogId; } else { // generate a permalink $url = BASE_URL."index.php?op=ViewArticle&blogId=".$blogId."&articleId=".$articleId; } printGET( $url ); } else { // post a comment to any of the articles of the given blog $url = BASE_URL."index.php"; // form values $form = Array ( "articleId" => $articleId, "op" => "AddComment", "commentTopic" => generateRandomWords(rand(1,15)), "commentText" => generateRandomParagraphs(rand(1,2)), "blogId" => $blogId, "userName" => "loadtest" ); // print the request printPOST( $url, $form ); } $numReqs++; } /** * outputs a line to perform a GET request */ Function printGET( $url ) { print( "GET, $url\n" ); } /** * outputs a line to perform a POST request */ function printPOST( $url, $formVars ) { $string = "POST, $url, \""; $form = Array(); foreach( $formVars as $key=>$value ) { $form[] = "$key=$value"; } $formString = implode( "|", $form ); $string .= "$formString\"\n"; print($string); } function generateRandomWord($lenght, $uppercase = false) { $newcode_length = 1; $newcode = ""; while($newcode_length < $lenght) { $a=97; $b=122; if ($newcode_length == 1) { if (rand(1,4) == 1 || $uppercase) { $a=65; $b=90; } } $code_part=chr(rand($a,$b)); $newcode_length++; $newcode = $newcode.$code_part; } return $newcode; } function generateRandomWords( $count, $uppercase = false, $html = true) { $words = generateRandomWord( rand( 3, 12), $uppercase ); for ($i = 1; $i < $count; $i++) { $rand = rand(3, 12); $words .= ' ' . generateRandomWord( $rand ); } return $words; } function generateRandomParagraph() { $length = rand( 3, 20 ); $counter = 0; $text = '

' . generateRandomWord( rand( 3, 12 ), true ); while ($counter < $length) { $word = generateRandomWords( rand(3, 12) ); $text = $text . ' ' . $word; $counter++; } $text .= "

"; return $text; } function generateRandomParagraphs( $count ) { $text = ''; for ($i = 1; $i < $count; $i++) { $text .= generateRandomParagraph(); } return $text; } ?>