PHP 8.5.0 Alpha 4 available for testing

Voting

: min(five, four)?
(Example: nine)

The Note You're Voting On

dosentnd at gmail dot com
5 years ago
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.

<< Back to user notes page

To Top