Hello,

I'm trying to develop a browser interface for my load testing environment.I can ssh into the client machines & run scripts,but also wish to execute them in stages.....kinda stuck here cz i do not know how to store the state of my counter variable...plz find below my code(i have left out the ssh2 and exec bits as the wud be very lengthy).I assume I'm missing something here and I would be really happy if anyone can point me in the right direction....


Admin Interface

<form action="form_action.php" method="GET">
No of Client Machines: <input type="text" name="number" /><br />
<input type="submit" value="GO" />

form_action

<?php
$number = $_GET['number'];
$machineValues = array("milan.surey.ac.uk", "chelsea.surey.ac.uk","unter.surey.ac.uk",
"winter.surey.ac.uk","ter.surey.ac.uk");

for ( $counter = 0; $counter < $number;$counter++) {
echo "$machineValues[$counter]\n";


}//end for
$newnumber = $_POST['number'];
$number=$newnumber + $counter;
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>New Machines:<input type='text' name='number'><input type='submit' value=' Submit '>   </form>";
  

?>

My desired output is :

No of machines : 1  // i enter 1
milan.surey.ac.uk 
New Machines : 'text box' SUBMIT // i enter 1 again

chelsea.surey.ac.uk 
New Machines : 'text box' SUBMIT // i enter 1 again

unter.surey.ac.uk
New Machines : 'text box' SUBMIT // i enter 1 again

Instead it works for the first loop

No of machines : 1 // i enter 1
milan.surey.ac.uk
Then prints out the
New Machines : 'text box' SUBMIT // i enter 1 again

Nothing happens.....

Well one obvious reason is the counter variable is initialized to 0 each time,for($counter =0....)How do i get around that?

Secondly,there needs to be a way to store the state of the $counter variable,so that it reflects in the next iteration


Lastly,is the highlighted form part correct?or should i get the new numbers in a diff variable as 'number' is used already once?

the purpose is I could use say 2 machines out of 8 for the test and then after a time delay use 5 and then the last one....

Plz help.Thanks in advance

Firstly, why do you use $_GET first and the $_POST later?
On the first run, your $_POST['number'] would be empty.

You could solve this by using sessions.

For example:

<?php
// Star the session. Myst be done before anything is added to the outpu.
session_start();

// Define your data
$data = array(/* your data here */);

// Get the data or use a default value.
($amount = @$_GET['amount']) or $amount = 1;
($startIndex = @$_SESSION['StartIndex']) or $startIndex = 0;

// Show the data
echo "<pre>";
for($i = $startIndex; $i < $startIndex + $amount; $i++) {
  echo $data[$i] . PHP_EOL; // PHP_EOL = the newline char for your OS
}
echo "</pre>";

// Set the session element, so we know where to start next time.
$_SESSION['StartIndex'] = $startIndex + $amount;
?>

<html>
<head><title>Test</title></head>
<body>

<form action="?" method="post">
  Amount to show: <input type="text" name="amount" /><br />
  <input type="submit" />
</form>

</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.