note 101793 added to function.ssh2-shell

From: Date: Tue, 11 Jan 2011 16:07:30 +0000
Subject: note 101793 added to function.ssh2-shell
Groups: php.notes 
Request: Send a blank email to php-notes+get-175645@lists.php.net to get a copy of this message
In my case the ssh2_shell doesn't work every time. There were many problems: - If I use stream_get_contents, the command(s) never executed - with while ($buf = fgets...) the loop never stops - without sleep(1) before stream_set_blocking, the command wasn't execute every time. Anyone knows why? That's what I made, and it works - but I think it isn't what it should be: <?php $strCommand = 'tar -C /path/to/extract -xjf /path/from/file.tar.bz2'; $sshStream = ssh2_shell($this->sshSession, 'xterm', null, 120, 24, SSH2_TERM_UNIT_CHARS); fwrite($sshStream, $strCommand . PHP_EOL); sleep(1); stream_set_blocking($sshStream, true); $sshUntarRetval = ""; while ($buf = fgets($sshStream,4096)) { flush(); $sshUntarRetval .= $buf; if (strpos($buf, 'tar -C') !== false) { break; } } fclose($sshStream); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 79.227.7.36 ---- Manual Page -- http://www.php.net/manual/en/function.ssh2-shell.php Edit -- https://master.php.net/note/edit/101793 Del: integrated -- https://master.php.net/note/delete/101793/integrated Del: useless -- https://master.php.net/note/delete/101793/useless Del: bad code -- https://master.php.net/note/delete/101793/bad+code Del: spam -- https://master.php.net/note/delete/101793/spam Del: non-english -- https://master.php.net/note/delete/101793/non-english Del: in docs -- https://master.php.net/note/delete/101793/in+docs Del: other reasons-- https://master.php.net/note/delete/101793 Reject -- https://master.php.net/note/reject/101793 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175645) next »