1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ssh using php

Discussion in 'PHP' started by ub007, Sep 10, 2008.

  1. ub007

    ub007 New Member

    Sep 10, 2008
    Likes Received:
    Trophy Points:
    I have setup an intranet of 10 machines(all running Ubuntu).One of them is the server hosting lets say Example Web Page. I use the other 9 machines to load test the server.Also intend to set up one PC as the master.So I have a master with 8 slaves testing www.example.com.The test scripts are installed on all the 9 machines & I have a browser form interface on my master node....

    The form looks like

    The GO button calls another php script which ssh s into the slave nodes and run the test scripts

    So i could do a test like ->
    load server(Example Web Page) using 3 client machines; stressing vector 'webserver' (//one of the many testing programs installed on the client machines)

    A sample php code would look (this is only for 3 machines)

    $machineValues = array("", "root", "password","david", "", "root", "password2","david2", "", "root2",
    if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't
    // log in at server1.example.com on port 22
    for ( $counter = 0; $counter < sizeof($machineValues); $counter =
    $counter+4) {
    if(!($con = ssh2_connect($machineValues[$counter], 22))){
    echo "fail: unable to establish connection\n";
    echo "Machine number $counter is $machineValues[$counter]";
    } else {
    // try to authenticate with username root, password secretpassword
        if(!ssh2_auth_password($con, $machineValues[$counter+1],
    $machineValues[$counter+2])) {
          echo "fail: unable to authenticate\n";
        } else {
        // allright, we're in!
           echo "okay: logged in...\n";
           // execute a command
           $stream = ssh2_exec($con, 'python/home/'.$machineValues[$counter+3].'/Desktop/hello.py');
           stream_set_blocking($stream, true);
           while($line = fgets($stream)) {
           echo $line."<br />";
    Now,lets say I select from the form

    No of Client MAchines : 1

    The code ssh into and runs the script.

    However i still got 'ip' => "" and 'ip' => "" available and I may wish to use that after a certain time delay...

    So i wish i could create some code that would enable the browser interface to give a message something like
    "you got 2 more machines available!" Would you like to add more?:thumbs:

    I would add one more field in the form
    More Client MAchines: <input type="text" name="machines" /><br />

    Eg.User selects 1, when they click submit,the PHP code should ssh into the next machine available which is ""....and then report back,"you got 1 more machine available!" and so on.......

    How would i do that?
  2. asha

    asha New Member

    Nov 9, 2006
    Likes Received:
    Trophy Points:
    Home Page:
    I don't know how much possible it is with PHP, but in Perl there are lot of modules at http://cpan.org to help you out.

Share This Page