note 87745 added to function.ssh2-exec

From: Date: Fri, 19 Dec 2008 04:07:10 +0000
Subject: note 87745 added to function.ssh2-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-148341@lists.php.net to get a copy of this message
I believe most of the problem that people are having here is that there is a misconception about what blocking *really* means. Blocking means a read from the *stream* will wait until there is data. Not necessarily all the data from the application -- but *some*. So it won't help you at all if you're executing a command that doesn't write to stdout, or writes a whole lot of data. So there are 2 problems: 1. If you need to know that a silent program is done via ssh2_exec, you'll need to signal it to yourself. ssh2_exec will *not* block execution until the command is done executing. And 2 consecutive ssh2_execs may execute asynchronously. You could also log into a shell via ssh2_shell and parse up to the next prompt -- but that's overkill. You can also do this by adding on some sort of sentinel at the end of your command, such as echo "@," and then block on reads until you see a "@." Ensure "@" won't appear in the output, or escape the output via some encoding mechanism if you can't do that. 2. If the program takes awhile, you have the same problem. You need to read until you're done. So you need a sentinel value like the above. 3. Sleep() is just a bad idea here. Commands rarely take the same amount of time to execute a command twice. It may be OK if you're doing *one* thing and can just wait 5 seconds. But that's not cool if it's something you're doing in a loop. I wrote a wrapper here -- http://www.seoegghead.com/software/ssh2-php-wrappers.seo Use it -- or get ideas from it. I hope this saves someone a bad day. Hope this helps! ---- Server IP: 209.41.74.194 Probable Submitter: 24.89.167.66 ---- Manual Page -- http://www.php.net/manual/en/function.ssh2-exec.php Edit -- https://master.php.net/note/edit/87745 Del: integrated -- https://master.php.net/note/delete/87745/integrated Del: useless -- https://master.php.net/note/delete/87745/useless Del: bad code -- https://master.php.net/note/delete/87745/bad+code Del: spam -- https://master.php.net/note/delete/87745/spam Del: non-english -- https://master.php.net/note/delete/87745/non-english Del: in docs -- https://master.php.net/note/delete/87745/in+docs Del: other reasons-- https://master.php.net/note/delete/87745 Reject -- https://master.php.net/note/reject/87745 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148341) next »