url($_GET['url']);
$lt->run($_GET['iterate']);
/**
*
* Class, ki na podanem URLju zacne izpolnjevati formo.
* Ce je na naslednji strani (ki jo dobi nazaj) zopet forma, nadaljuje izpolnjevanje (za izpolnjevanje celotne ankete na vecih straneh)
*
* Izpolnjevanje od zacetka se pozene v podanem stevilu iteracij.
*
*/
class LoadTest {
private $time_start;
private $start;
private $url;
private $subrequests = false;
/**
* zabelezimo zacetek izvajanja skripte
*
*/
function __construct () {
$this->start = microtime(true);
}
/**
* URL na katerem bomo zaceli izpolnjevati formo
*
* @param mixed $url
*/
function url ($url) {
$this->url = $url;
}
/**
* pozenemo izpolnjevanje forme v stevilu iteracij
*
* @param mixed $iterate
*/
function run ($iterate = 1) {
for ($i=1; $i<=$iterate; $i++) {
$this->time_start = microtime(true);
$this->fill_form($this->url);
$time_seconds = microtime(true) - $this->time_start;
echo $i.'. form filled in '.$time_seconds.' seconds
';
flush(); @ob_flush();
}
$time_seconds = microtime(true) - $this->start;
echo '
All '.$iterate.' forms filled in '.$time_seconds.' seconds';
flush(); @ob_flush();
}
/**
* izpolnjuje nek form, dokler ne pride do strani brez form elementa
*
* @param string $url
* @param mixed $post
*/
function fill_form ($url, $post=null) {
if ($url == '') return;
$i = 0;
do {
list($header, $content) = $this->post_request($url, $post);
if ($this->subrequests) {
$this->post_request('http://www.1ka.si/admin/survey/minify/g=jsfrontend');
$this->post_request('http://www.1ka.si/admin/survey/script/calendar/calendar.js');
$this->post_request('http://www.1ka.si/admin/survey/script/calendar/lang/calendar-si.js');
$this->post_request('http://www.1ka.si/admin/survey/script/calendar/calendar-setup.js');
$this->post_request('http://www.1ka.si/admin/survey/script/calendar/calendar.css');
$this->post_request('http://www.1ka.si/main/survey/skins/Default.css');
}
$url = '';
// ce stran poslje redirect
if (strpos($header, 'HTTP/1.1 302 Found') !== false) {
$h = explode("\n", $header);
foreach ($h AS $l) if (strpos($l, 'Location:') !== false) $location = $l;
$url = trim( substr($location, 10) );
$post = null;
// obicen page, ki ga gremo parsat
} else {
$form = $this->parse_form($content);
if ( isset($form['action']) ) $url = $form['action'];
$form['input'] = $this->randomize_form($form['input']);
if ( isset($form['input']) ) $post = $form['input'];
}
if (++$i >= 10000) { echo 'BREAK'; break; } // preprecimo, da se ne zacikla
} while ($url != '');
/*if (strpos($content, 'Hvala za sodelovanje') === false)
echo '
'; echo "\noriginale: "; print_r($form);*/ if ( count($form) == 0 ) return $form; foreach ($form AS $key => $input) { // radio button - izberemo enega nakljucno if ($input['type'] == 'radio') { $pos = rand(0, count($input)-2); $form[$key] = $input[$pos]; // checkbox (razlika je v tabeli in navadnih, ker imajo razlicen nacin poimenovanja, in se ne da drugace zaznati skupin... zakompliciran..) } elseif ($input['type'] == 'checkbox') { // navaden checkbox - izberemo enega nakljucno if ( count($input) > 2 ) { $pos = rand(0, count($input)-2); $form[$key] = $input[$pos]; // multigrid checkbox - vsak checkbox obkljukamo z verjetnostjo 50% (ker se ne da razbrati vrstic zaradi takega poimenovanja) } else { foreach ($input AS $k => $v) { if ($v != 'checkbox') if (rand(0,1) >= 0.5) $form[$key] = $v; else unset($form[$key]); } } // textfield - vpisemo nek random string } elseif ($input['type'] == 'text') { $form[$key] = ($_GET['uniqueID']!=''?$_GET['uniqueID'].'-':'') . substr(sha1(rand(0,1).time()), 0, 10); // ce je samo 1 element, nimamo kaj randomizirat (count je 2, ker je en type) } else { $form[$key] = $input[0]; } } /*echo "\nrandomized:"; print_r($form); echo '';*/ return $form; } /** * en primercek, ki poslje vse parametre. request_show.php pa izpise vse post, get in cookieje ki jih prejme * */ function test_example() { $post = array('test' => 'foobar', 'okay' => 'yes', '6' => 'test'); $get = array ('get'=>'gett', 'get222'=>'123'); $cookie = array ('ena' => 'prvi', 'dva' => 'drugiff'); list($header, $content) = $this->post_request( "http://test.1ka.si/utils/request_show.php?pa_v_urlju=tudi_dela", $post, $get, $cookie ); echo $header.'