我有两个服务器,
我有以下代码,我放入服务器A,
<?php $submit = $_POST['submit'];
if($submit == "Restart") {
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't
exist");
if(!($con = ssh2_connect("x.x.x.x", 22))){
echo "fail: unable to establish connection\n";
} else {
if(!ssh2_auth_password($con, "user", "password")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "OK: logged in...end Restart\n";
// execute a command
if (!($stream = ssh2_exec($con, "service bind9 restart" ))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
echo "<pre>";
echo $data; //Prints the output
echo "</pre>";
}
}
}
} echo '<form action="" method="post"
<input type="submit" name="submit" value="Restart"></form>';
?>
问题是,当我从服务器A执行代码时, 服务器B不想重启。 但是,当我改变代码命令,如&#34; dmesg,ifconfig,whoami&#34;代码是工作,我只想重启服务bind9 我们可以做这个模拟.. 谢谢你的帮助