Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ...
- ...
- //while there are still jobs that are not done..
- while (1) {
- //wait for 10 seconds and query again...
- sleep(10);
- $statusResult = mysqli_query($dbConnection, $qStatus);
- //if there are undone jobs we pick them and execute them
- if (mysqli_num_rows($statusResult) > 0){
- //query the next undone test case
- $testResult = mysqli_query($dbConnection, $qNextTest);
- //fetch the returned query object and store needed parameters
- $row = $testResult->fetch_assoc();
- $id = $row['id'];
- $test_script = $row['test_script'];
- $gateway = $row['gateway'];
- if ($connection = @ssh2_connect($gateway, 22)) {
- ssh2_auth_password($connection, $user, $password);
- //execute the test case
- $stream = ssh2_exec($connection, "/my/path/to/script.sh");
- //fetch output stream and stderr
- stream_set_blocking($stream, true);
- $stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
- $stream_err = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
- while($line = fgets($stream_out)) {flush(); echo '<pre>' . $line . '</pre>';}
- echo '<pre>' . "------------------------n" . '</pre>';
- while($line = fgets($stream_err)) {flush(); echo '<pre>' . $line . '</pre>';}
- fclose($stream);
- //update the table after the above script is done
- $qUpdateStatus = "UPDATE table SET status = 1 WHERE id = $id";
- $updateresult = mysqli_query($dbConnection, $qUpdateStatus);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement