note 124818 added to function.ssh2-exec
| From: | dosentnd at gmail dot com | Date: | Thu, 12 Mar 2020 08:39:08 +0000 |
| Subject: | note 124818 added to function.ssh2-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214318@lists.php.net to get a copy of this message | ||
Running multiple commands shows this warning and second(and any next) command wont be executed:
- PHP Warning: ssh2_exec(): Unable to request a channel from remote host in ...
Solution with fclose($stream) does not work, but this is simple solution which works for me:
<?php
$connection = ssh2_connect('SOME SSH IP ADDRESS', 22);
ssh2_auth_password($connection, 'username', 'passwortd');
//those commands are for some HUAWEI enterprise routers
$stream = ssh2_exec( $connection, "screen-length 0 temporary\ndisplay isis name-table"
);
stream_set_blocking( $stream, true );
$stream_out = ssh2_fetch_stream( $stream, SSH2_STREAM_STDIO );
echo stream_get_contents($stream_out);
?>
first command is: screen-length 0 temporary
second command is: display isis name-table
which is executed with \n in the same line.
You have to separete outputs of those commands later.
Looks like ssh2_exec allocates exec stream in session you are connected in, and for freeing it , you
have to ssh2_disconnect.
Usualy you are ok to ssh2_exec one command then disconnect, then connect and ssh2_exec next command.
This is how some other php libraries works as I have seen. But sometimes some variables are sesion
dependent, and when you disconnect variables resets.
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.195 (proxied: 212.200.247.77)
----
Manual Page -- http://php.net/manual/en/function.ssh2-exec.php
Edit -- https://master.php.net/note/edit/124818
Del: integrated -- https://master.php.net/note/delete/124818/integrated
Del: useless -- https://master.php.net/note/delete/124818/useless
Del: bad code -- https://master.php.net/note/delete/124818/bad+code
Del: spam -- https://master.php.net/note/delete/124818/spam
Del: non-english -- https://master.php.net/note/delete/124818/non-english
Del: in docs -- https://master.php.net/note/delete/124818/in+docs
Del: other reasons-- https://master.php.net/note/delete/124818
Reject -- https://master.php.net/note/reject/124818
Search -- https://master.php.net/manage/user-notes.php