public function collectResults() { for ($i = 0, $t = pssh_tasklist_first($this->psshTaskHandler); $t; $i++, $t = pssh_tasklist_next($this->psshTaskHandler)) { $report = $this->taskReports[$i]; if ($report->getPsshTaskType() != pssh_task_type($t)) { throw new \UnexpectedValueException(sprintf('collectTaskReports() expects type %s for task "%s", %s given.', $report->getPsshTaskType(), (string) $report, pssh_task_type($t))); } $report->setStatus(pssh_task_status($t))->setExitStatus(pssh_task_exit_status($t))->setOutput(pssh_task_stdout($t))->setErrorOutput(pssh_task_stderr($t)); } }
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 { } while (pssh_tasklist_exec($tl, $server, 10) == PSSH_RUNNING); /* output a report */ $failed = $succeeded = 0; for ($t = pssh_tasklist_first($tl); $t; $t = pssh_tasklist_next($tl)) { if (pssh_task_status($t) == PSSH_TASK_DONE) { $succeeded++; } else { $failed++; } } echo "Commands succeeded: " . $succeeded . "\n"; echo "Commands failed: " . $failed . "\n";