首先,php需要支持ssh2的扩展。

1登陆

$connection=ssh2_connect($ip,$port);

ssh2_auth_password($connection,$username,$password);

2执行命令

$get_devices = "adb devices";

$stream = ssh2_exec($connection , $get_devices);

3获取命令执行结果

stream_set_blocking($stream, true);

$output = stream_get_contents($stream);

fclose($stream);

此时,获取string类型的output。