note 95302 deleted from function.ssh2-exec by danbrown
| From: | danbrown@php.net | Date: | Fri, 25 Dec 2009 06:17:24 +0000 |
| Subject: | note 95302 deleted from function.ssh2-exec by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164320@lists.php.net to get a copy of this message | ||
Note Submitter: bothmeans at gmail dot com
----
ssh2_exec() is buggy as all get out. As posts below this one have noted, it frequently only returns
a portion of the desired output and that's assuming it returns anything at all.
sleep() often fixes this but using sleep() in a for loop is a bad idea. jaimie at seoegghead dot
com suggests using a "sentinel character" but not even that's fool proof. Try, for
example, to cat an arbitrary file - can you guarantee that the "sentinel character"
won't appear in the output? He also suggests that you can "escape the output via some
encoding mechanism" but that doesn't work, either. Besides, how does he propose that be
done, anyway? Maybe cat filename.ext | urlencode? I have no clue but that shouldn't be
necessary, anyway.
phpseclib (http://phpseclib.sourceforge.net/) - a pure-PHP implementation of SSH - makes this a
non-issue as it returns all the output all the time.
The reason the ssh2 PECL extension doesn't is because uses channels of type 'shell'
and not of type 'exec'. With 'exec', you read from the channel until the
channel is closed. With 'shell', the channel is never closed by the server and as such
you have no way of knowing how much reading needs to be done. Also, 'shell' is just more
time consuming then 'exec' - in my experience, it's as though 'shell' tries
to throttle the output so it doesn't display too fast. That may be nice in an interactive
shell but in a library it's not at all desirable.