L
L
linuxnb2018-11-17 02:57:35
PHP
linuxnb, 2018-11-17 02:57:35

How to send commands from under PHP via ssh and get a response?

Good time of the day,
I try to send a string from under php via ssh and get a response
, but there is silence in response, I hope that someone will tell you

$connection = ssh2_connect('localhost', 22);
ssh2_auth_password($connection, 'root', '0000000');

$stream = ssh2_exec($connection, 'top');


stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
print_r( stream_get_contents($stream_out));

thanks in advance to those who respond

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-11-17
@Minifets

The top command runs a program that runs in real time in the console and has no output. Try running the command with the following options: "top -b -n1".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question