Example #1
0
<?php

$servers = array("<server1>", "<server2>");
$user = "******";
$public_key = "<key.pub>";
$remote_file = "<remote file>";
$local_file = "<local file>";
$r = pssh_init($user, $public_key);
foreach ($server as $server) {
    pssh_server_add($r, $server);
}
/* connect to the servers */
do {
    $ret = pssh_connect($r, $server, 3);
    switch ($ret) {
        case PSSH_CONNECTED:
            echo "connected to ", $server, "\n";
            unset($servers[array_search($server, $servers)]);
            break;
    }
} while ($ret == PSSH_CONNECTED);
if ($ret == PSSH_SUCCESS) {
    echo "all servers connected\n";
} else {
    echo "failed to connect to: ", implode(", ", $servers), "\n";
}
/* create a task */
$tl = pssh_tasklist_init($r);
pssh_copy_to_server($tl, $server, $local_file, $remote_file);
/* execute the task */
do {
Example #2
0
File: Dplr.php Project: muxx/dplr
 /**
  * Do connecting to servers.
  *
  * @access protected
  * @return void
  */
 protected function connectToServers()
 {
     $servers = $this->servers;
     $this->timers['connection'] = new \DateTime();
     do {
         $ret = pssh_connect($this->pssh, $server, $this->connTimeout);
         switch ($ret) {
             case PSSH_CONNECTED:
                 unset($servers[$server]);
                 break;
         }
     } while ($ret == PSSH_CONNECTED);
     $this->timers['connection'] = $this->timers['connection']->diff(new \DateTime());
     if (PSSH_SUCCESS !== $ret) {
         throw new ConnectionFailedException($servers);
     }
 }