I am trying to retrieve a stream of data that comes from an ssh connection. When I use putty to ssh in, I will just start getting data on the screen, no commands were needed.
Now I am trying to do the same thing but in php to manipulate the data and save it to a database. For this task I have already installed the necessary package for ssh2 and was able to get a connection. But I don't know how to get that data. My overall goal is to have this script running as a daemon and continually retrieve information to save.
I have tried using ssh2_shell and use the returned stream resource by stream_get_contents but it returns false.
$stdio_stream = ssh2_shell($connection);
$contents = get_resource_type ($stdio_stream);
echo $contents;
$contents = stream_get_contents ($stdio_stream);
if ($contents) {
print_r($contents);
} else {
echo 'it failed';
}
And I have tried this as per User Contributed Notes
$stdout_stream = ssh2_exec($connection, "/bin/ls -la /tmp");
$dio_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDIO);
$result_dio = stream_get_contents($dio_stream);