I've managed to get a working example of simple ping on localhost via live output (see below), but using SSH2 to connect and then execute commands against a remote machine and display the results via live output is a completely separate issue. I've scoured Google all over the place and it seems like popen() and flush() are the key but I'm just not sure how to make it work.
The main question is this: how would I use ssh2_connect() and then output live results of "ls" using popen()? I figure if I can get that to work with live results, then I can handle the rest via trial and error of replacing "ls" with whatever Shell commands I need (such as issuing a command to execute a Shell file).
Code: Select all
<?php
header('Content-Encoding: none;');
set_time_limit(0);
$cmd = "ping 127.0.0.1";
$handle = popen($cmd, "r");
if (ob_get_level() == 0)
ob_start();
while(!feof($handle)) {
$buffer = fgets($handle);
$buffer = trim(htmlspecialchars($buffer));
echo $buffer . "<br />";
echo str_pad('', 4096);
ob_flush();
flush();
usleep(1);
}
pclose($handle);
ob_end_flush();
?>