note 65127 added to function.ssh2-exec

From: Date: Mon, 24 Apr 2006 21:17:12 +0000
Subject: note 65127 added to function.ssh2-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-109613@lists.php.net to get a copy of this message
mao at nospam dot com made a typo in his initial code, that's why feof() doesn't seem to work. feof() (and other functions for a resource of type stream) work fine on the resource returned by this function The correct version of his initial example is: <?php $filename = "eg.txt"; $stream0 = ssh2_exec($conn, "stat $filename"); if($stream0) { $i = 1; // Notice the variable name is $stream0 and not $stream while( !feof($stream0) ) { $line = fgets($stream0) ; echo "<br>Line $i ==> $line"; $i += 1; } ?> Also <?php while($line=fgets($stream0)){ } ?> Won't work properly if you get an empty string back as part of the output, if you don't want to use feof, but really want to use fgets in the while use this: <?php ...... while(($line=fgets($stream0)) !== false){ echo "<br>Line $i ==> $line"; $i += 1; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 66.236.175.18 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.ssh2-exec.php Edit -- http://master.php.net/note/edit/65127 Del: integrated -- http://master.php.net/note/delete/65127/integrated Del: useless -- http://master.php.net/note/delete/65127/useless Del: bad code -- http://master.php.net/note/delete/65127/bad+code Del: spam -- http://master.php.net/note/delete/65127/spam Del: non-english -- http://master.php.net/note/delete/65127/non-english Del: in docs -- http://master.php.net/note/delete/65127/in+docs Del: other reasons-- http://master.php.net/note/delete/65127 Reject -- http://master.php.net/note/reject/65127 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#109613) next »