1
我试图从远程服务器运行一个SSH命令,使用ssh2
函数,使用ssh2
函数库。SSH2返回“类型(流)的资源(2)”(PHP)
非但没有什么我想从SSH返回给我,我得到这个:
resource(2) of type (stream)
有时2
是3
如果该事项。
这里是我尝试使用代码:
<?php
$connection = ssh2_connect('ssh.example.com', 22);
ssh2_auth_password($connection, 'root', 'password');
if($output = ssh2_exec($connection, 'uptime')) {
var_dump($output);
}
工作液:
<?php
$connection = ssh2_connect('ssh.example.com', 22);
ssh2_auth_password($connection, 'root', 'password');
if($output = ssh2_exec($connection, 'uptime')) {
stream_set_blocking($output, true);
echo stream_get_contents($output);
}
以前从来没有处理过“流”。我如何才能从“流”中获取数据? –
@JoshFoskett:您可以使用['stream_get_contents()'](http://php.net/stream_get_contents)读取流直到结束。 –
echo(stream_get_contents($ stream)); – Interrobang