Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <?php
  2.  
  3. ...
  4. ...
  5.  
  6. //while there are still jobs that are not done..
  7. while (1) {
  8. //wait for 10 seconds and query again...
  9. sleep(10);
  10. $statusResult = mysqli_query($dbConnection, $qStatus);
  11. //if there are undone jobs we pick them and execute them
  12. if (mysqli_num_rows($statusResult) > 0){
  13. //query the next undone test case
  14. $testResult = mysqli_query($dbConnection, $qNextTest);
  15.  
  16. //fetch the returned query object and store needed parameters
  17. $row = $testResult->fetch_assoc();
  18. $id = $row['id'];
  19. $test_script = $row['test_script'];
  20. $gateway = $row['gateway'];
  21.  
  22.  
  23. if ($connection = @ssh2_connect($gateway, 22)) {
  24. ssh2_auth_password($connection, $user, $password);
  25.  
  26. //execute the test case
  27. $stream = ssh2_exec($connection, "/my/path/to/script.sh");
  28.  
  29. //fetch output stream and stderr
  30. stream_set_blocking($stream, true);
  31. $stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
  32. $stream_err = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
  33. while($line = fgets($stream_out)) {flush(); echo '<pre>' . $line . '</pre>';}
  34. echo '<pre>' . "------------------------n" . '</pre>';
  35. while($line = fgets($stream_err)) {flush(); echo '<pre>' . $line . '</pre>';}
  36. fclose($stream);
  37.  
  38. //update the table after the above script is done
  39. $qUpdateStatus = "UPDATE table SET status = 1 WHERE id = $id";
  40. $updateresult = mysqli_query($dbConnection, $qUpdateStatus);
  41. }
  42.  
  43. }
  44. }
  45.  
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement