note 53691 modified in function.ssh2-exec by danbrown

From: Date: Wed, 17 Feb 2010 14:55:33 +0000
Subject: note 53691 modified in function.ssh2-exec by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166072@lists.php.net to get a copy of this message
If you want to run many exec orders throught ssh2 in the same process using the same variable $stream for exemple and to read the output for each order, you must close the stream after each order else you will not be able to read the next order output. <?php $stream=ssh2_exec($conn_id,"/usr/bin/ls ."); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); if(ereg("public_html",$cmd)){ // ........................................... } $stream=ssh2_exec($conn_id,"/usr/bin/ls public_html"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); if(ereg("images",$cmd)){ // .......................................... } $stream=ssh2_exec($conn_id,"/usr/bin/ls public_html/images"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); if(ereg("blabla",$cmd)){ // .......................................... } ?> --was-- If you want to run many exec orders throught ssh2 in the same process using the same variable $stream for exemple and to read the output for each order, you must close the stream after each order else you will not be able to read the next order output. $stream=ssh2_exec($conn_id,"/usr/bin/ls ."); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); if(ereg("public_html",$cmd)){ ........................................... } $stream=ssh2_exec($conn_id,"/usr/bin/ls public_html"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); if(ereg("images",$cmd)){ .......................................... } $stream=ssh2_exec($conn_id,"/usr/bin/ls public_html/images"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); if(ereg("blabla",$cmd)){ .......................................... } http://php.net/manual/en/function.ssh2-exec.php

« previous php.notes (#166072) next »