note 95301 added to function.ssh2-exec
| From: | bothmeans at yahoo dot com | Date: | Fri, 25 Dec 2009 06:14:24 +0000 |
| Subject: | note 95301 added to function.ssh2-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164317@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 192.41.40.227
Probable Submitter: 66.68.45.157
----
Manual Page -- http://www.php.net/manual/en/function.ssh2-exec.php
Edit -- https://master.php.net/note/edit/95301
Del: integrated -- https://master.php.net/note/delete/95301/integrated
Del: useless -- https://master.php.net/note/delete/95301/useless
Del: bad code -- https://master.php.net/note/delete/95301/bad+code
Del: spam -- https://master.php.net/note/delete/95301/spam
Del: non-english -- https://master.php.net/note/delete/95301/non-english
Del: in docs -- https://master.php.net/note/delete/95301/in+docs
Del: other reasons-- https://master.php.net/note/delete/95301
Reject -- https://master.php.net/note/reject/95301
Search -- https://master.php.net/manage/user-notes.php