php远程连接到外部服务器,并执行linux命令,实时获取返回值

服务端用web,里面的程序可以执行系统命令,用system函数,然后web访问就可以了。这种方式的缺点是执行时间不能太长。
■网友
正好看这个,直接发给你代码: $hostuser = "root"; $sshpasswd = "password"; $connection = ssh2_connect(\u0026#39;host\u0026#39;,"22"); $auth_methods = ssh2_auth_none($connection, $hostuser); if(in_array(\u0026#39;password\u0026#39;,$auth_methods)){ if (ssh2_auth_password($connection, $hostuser, $sshpasswd)){ $stream = ssh2_exec($connection, "cat hello.php"); stream_set_blocking($stream, true); if ($stream === FALSE) die("command exec failed!"); echo \u0026#39;\u0026lt;pre\u0026gt;\u0026#39;.stream_get_contents($stream).\u0026#39;\u0026lt;/pre\u0026gt;\u0026#39;; }else{ echo "ssh connect failed"; } }else{ echo "Login failed"; }


    推荐阅读