Closed dcortez closed 6 years ago
The reason it is hanging is likely you executing a command and getting stuck at the ---more--- prompt.
If you want to get around that and continue using the ->exec() function you will have to send multiple lines in the command such as "terminal length 0\nshow cable modem".
Alternately you can write a wrapper that uses ->read() and ->write() combined with prompt detection to interactively send and parse multiple commands in a single ssh session. I have an example at https://github.com/metaclassing/PHP7-SSHWrapper used for exactly this purpose.
Thanks for posting your SSHWrapper example. It seems I must have been missing something and your code seems to resolve my issue.
So in the stacktrace we can see that the destructor is called but then when the destructor tries to send what is presumably a NET_SSH2_MSG_DISCONNECT packet but it can't because the server is closed and thus you're encountering that error.
Anyway, I think the issue is that some servers - routers in particular - just don't support multiple exec's. http://www.frostjedi.com/phpbb3/viewtopic.php?p=117471#p117471 talks about this issue some.
metaclassing's suggestion should work since I guess his lib uses approaches that may well only work on routers to kinda emulate multiple exec()'s.
I am trying to use this library (version 2.0.9) in a Laravel project to connect to a Cisco CMTS in order to get data about modems on our system. I have successfully used this code in the past on a Codeigniter project (in fact, running on the same server). The only difference I can see is I am using an older version (not sure which) of the library in my Codeigniter project vs my Laravel project.
The test code I am running is exactly the same between the two frameworks and is as follows:
In my testing, if I remove the $ssh->exec line, the script does not error out and the logs show it logs in and out perfectly. Once I add the exec in is where I get the connection closed error.
We are testing this on a lab cmts on a private IP so won't be able to give that information, but I am hoping that with the log you will see something I am missing.
Error Stack:
Log: